From 0488df2ed16e0afd369656a4c4f9359cdc73f6f7 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Mon, 25 Apr 2022 00:43:53 -0500 Subject: [PATCH] Switched to using ASP.Net Core localization. --- Props/Pages/Index.cshtml | 72 +++++++++++++------ Props/Pages/Search.cshtml | 23 +++--- .../Services/Textual/CachedTextualManager.cs | 29 -------- Props/Services/Textual/ITextualManager.cs | 8 --- Props/Startup.cs | 2 - Props/appsettings.json | 3 - Props/textual/Index.json | 34 --------- Props/textual/search.json | 16 ----- 8 files changed, 62 insertions(+), 125 deletions(-) delete mode 100644 Props/Services/Textual/CachedTextualManager.cs delete mode 100644 Props/Services/Textual/ITextualManager.cs delete mode 100644 Props/textual/Index.json delete mode 100644 Props/textual/search.json diff --git a/Props/Pages/Index.cshtml b/Props/Pages/Index.cshtml index dbfcf9c..bc03500 100644 --- a/Props/Pages/Index.cshtml +++ b/Props/Pages/Index.cshtml @@ -1,7 +1,7 @@ @page -@using Props.Services.Content +@using Microsoft.AspNetCore.Mvc.Localization @model IndexModel -@inject ITextualManager ContentManager +@inject IViewLocalizer Localizer @{ ViewData["Title"] = "Home page"; } @@ -14,7 +14,7 @@

Props

- @ContentManager.Json.description + @Localizer["description"]

@@ -22,7 +22,7 @@
-

@ContentManager.Json.help.title

+

@Localizer["help.title"]

- @ContentManager.Json.help.searchIntroduction + @Localizer["help.searchIntroduction"]

- @ContentManager.Json.help.additionalInfo + @Localizer["help.additionalInfo"]

@@ -42,7 +42,7 @@

Our Mission

- @ContentManager.Json.mission + @Localizer["mission"]

@@ -52,25 +52,55 @@

Features

- @ContentManager.Json.features.description + @Localizer["features.description"]

- @foreach (dynamic feature in ContentManager.Json.features.list) - { -
-
-
@feature.title
-
- @feature.subtitle -
-

- @feature.text -

-
+
+
+
@Localizer["feature.shoppingList.title"]
+
+ @Localizer["feature.shoppingList.subtitle"] +
+

+ @Localizer["feature.shoppingList.text"] +

- } +
+
+
+
@Localizer["feature.productComparison.title"]
+
+ @Localizer["feature.productComparison.subtitle"] +
+

+ @Localizer["feature.productComparison.text"] +

+
+
+
+
+
@Localizer["feature.autoSearch.title"]
+
+ @Localizer["feature.autoSearch.subtitle"] +
+

+ @Localizer["feature.autoSearch.text"] +

+
+
+
+
+
@Localizer["feature.sharing.title"]
+
+ @Localizer["feature.sharing.subtitle"] +
+

+ @Localizer["feature.sharing.text"] +

+
+
\ No newline at end of file diff --git a/Props/Pages/Search.cshtml b/Props/Pages/Search.cshtml index 92d9400..a8a287b 100644 --- a/Props/Pages/Search.cshtml +++ b/Props/Pages/Search.cshtml @@ -1,7 +1,7 @@ @page -@using Props.Services.Content +@using Microsoft.AspNetCore.Mvc.Localization @model SearchModel -@inject ITextualManager ContentManager +@inject IViewLocalizer Localizer @{ ViewData["Title"] = "Search"; @@ -236,10 +236,10 @@

Quick Picks


@@ -257,7 +257,7 @@
@@ -266,10 +266,10 @@

Results


@@ -280,7 +280,7 @@ @@ -290,10 +290,9 @@

Get Started!

    - @foreach (string instruction in ContentManager.Json.instructions) - { -
  1. @instruction
  2. - } +
  3. @Localizer["instructions.type"]
  4. +
  5. @Localizer["instructions.configure"]
  6. +
  7. @Localizer["instructions.search"]
diff --git a/Props/Services/Textual/CachedTextualManager.cs b/Props/Services/Textual/CachedTextualManager.cs deleted file mode 100644 index 761e8a2..0000000 --- a/Props/Services/Textual/CachedTextualManager.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.IO; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json.Linq; -using Props.Options; - -namespace Props.Services.Content -{ - public class CachedTextualManager : ITextualManager - { - private dynamic data; - private readonly TextualOptions options; - private readonly string fileName; - - dynamic ITextualManager.Json - { - get - { - if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName))); - return data; - } - } - - public CachedTextualManager(IConfiguration configuration) - { - this.options = configuration.GetSection(TextualOptions.Textual).Get(); - this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json"; - } - } -} \ No newline at end of file diff --git a/Props/Services/Textual/ITextualManager.cs b/Props/Services/Textual/ITextualManager.cs deleted file mode 100644 index 7005827..0000000 --- a/Props/Services/Textual/ITextualManager.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Props.Services.Content -{ - public interface ITextualManager - { - // TODO: Replace this system with globalization and localization. See: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-6.0 - dynamic Json { get; } - } -} \ No newline at end of file diff --git a/Props/Startup.cs b/Props/Startup.cs index 0c4d6f8..36f1ef2 100644 --- a/Props/Startup.cs +++ b/Props/Startup.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Props.Data; using Props.Models.User; -using Props.Services.Content; using Props.Services.Modules; using System; @@ -47,7 +46,6 @@ namespace Props .AddEntityFrameworkStores(); services.AddRazorPages(); - services.AddSingleton(typeof(ITextualManager<>), typeof(CachedTextualManager<>)); services.AddSingleton(); services.AddScoped(); services.AddScoped(); diff --git a/Props/appsettings.json b/Props/appsettings.json index 8d5beea..6bac999 100644 --- a/Props/appsettings.json +++ b/Props/appsettings.json @@ -18,9 +18,6 @@ "Search": { "MaxResults": 100 }, - "Textual": { - "Dir": "./textual" - }, "Metrics": { "MaxQueryWords": 4096, "MaxProductListings": 1024 diff --git a/Props/textual/Index.json b/Props/textual/Index.json deleted file mode 100644 index 21d66d0..0000000 --- a/Props/textual/Index.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "description": "Props is a community driven website meant to help with organizing your online component shopping experience. Create project component lists, search across multiple commonly used online retail stores and share your projects with rest of the community!", - "help": { - "title": "Getting Started", - "searchIntroduction": "Props is a site designed to help with the online project component shopping experience. Create project component lists and search across multiple commonly used online retail stores to find the ideal purchase.", - "additionalInfo": "Take advantage of our project component manager, where you can add detailed descriptions of what things are for, as well as overall project summaries." - }, - "mission": "Our mission is to bring become digital project workshop for anyone who likes Do It Yourself (DIY), Internet Of Things (IOT), or really any project that needs a home for all the materials, ideas, and thoughts. We also strive to build a community of builders, crafters and creators in hopes that we can all learn from each other's projects.", - "features": { - "description": "Props strives to be a platform where people can find and organize the material they need to complete their projects. Our features are therefore tailored to the community helping each other, as well as smart tools to quickly compare different products from different stores.", - "list": [ - { - "title": "Shopping List", - "subtitle": "We'll do it so you don't need to.", - "text": "We'll help you track the components you need. You can add descriptions, and mark things as purchased, or shipped at your convenience. You can even add components from stores that Props doesn't know about yet!" - }, - { - "title": "Product Comparison", - "subtitle": "So many shops to look through...", - "text": "There's so many online retailers nowadays that it's becoming more and more work to check all of them for what you need. With us, we'll do the searching for you. All you need to do is decide if the shipping time, cost, ratings and reviews are suitable!" - }, - { - "title": "Auto Listing Search", - "subtitle": "Need a starting point?", - "text": "Some project parts commonly used. We'll try and find these parts for you automatically. This means you can create a shopping list, and we'll try and the best fitting products for you based on your shopping list entries." - }, - { - "title": "Share It!", - "subtitle": "Show off your work!", - "text": "Have a project that you're excited about? Want to tell all your friends? We'll help. Each of your projects has a privacy setting. You can have it publically listed, unlisted, or completely private. Short link included." - } - ] - } -} \ No newline at end of file diff --git a/Props/textual/search.json b/Props/textual/search.json deleted file mode 100644 index 9b3d4aa..0000000 --- a/Props/textual/search.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "instructions": [ - "Type in the electronic component your looking for in the search bar above.", - "Optionally, hit the configure button to modify your search criteria. With an account, you can even create and save multiple search profiles known as \"search outlines\".", - "That's it! Hit search and we'll look far and wide for what you need!" - ], - "quickPicks": { - "searched": "The cream of the crop!", - "prompt": "This is where we'll show you top listings so you can get back to working on your project!" - }, - "results": { - "searched": "We searched far and wide. Here's what we found!", - "prompt": "This is were we'll display all the results we went through to show you the top. This is a good place to check if none of our quick picks cater to your needs." - }, - "notSearched": "Nothing to show yet!" -} \ No newline at end of file