Skip to content

Commit

Permalink
refactor(i18n) Re-write i18n layer to use TS files (#29)
Browse files Browse the repository at this point in the history
This makes the issue to use JSON modules obsolete as we get type safety and avoid calling any functions now.
  • Loading branch information
dhardtke committed Apr 22, 2021
1 parent 881a823 commit 233e869
Show file tree
Hide file tree
Showing 19 changed files with 404 additions and 308 deletions.
4 changes: 1 addition & 3 deletions dev/dev_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ if (import.meta.main) {
watchPaths: [
"src",
"assets",
"i18n",
"deps.ts",
"lock.json",
],
actions: [
{
id: "Server",
match:
/(deps\.ts|lock\.json|\/src\/(.+)\.(ts|html))|(\/i18n\/.+\.json)/,
match: /(deps\.ts|lock\.json|\/src\/(.+)\.(ts|html))/,
fn: process(
undefined,
"deno",
Expand Down
117 changes: 0 additions & 117 deletions i18n/en.json

This file was deleted.

5 changes: 4 additions & 1 deletion src/http/webserver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { log, Oak } from "../../deps.ts";
import { Database } from "../data/db.ts";
import { services } from "../data/service/services.ts";
import { Settings } from "../settings.ts";
import { ingredient } from "../data/util/ingredient.ts";
import { en } from "../i18n/en.ts";
import { setLanguage } from "../i18n/mod.ts";
import { Settings } from "../settings.ts";
import { Page } from "../tpl/templates/_structure/page.ts";
import { orderByAdapter } from "./adapters/order_by_adapter.ts";
import { paginationAdapter } from "./adapters/pagination_adapter.ts";
Expand Down Expand Up @@ -44,6 +46,7 @@ export async function spawnServer(
args.settings.ingredientSortOrder,
args.settings.ingredientUnitPostprocessing,
);
setLanguage(en);
Page.minifying = args.settings.minifyHtml;

const app = new Oak.Application<AppState>({
Expand Down
120 changes: 120 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { Language } from "./mod.ts";

export const en: Language = {
appName: "CookGuide",
cancel: "Cancel",
confirmation: "Confirmation",
create: "Create",
createdAt: "Created",
delete: "Delete",
description: "Description",
down: "Down",
edit: "Edit",
error: {
404: {
description: "The page you are looking for can not be found.",
title: "Not Found",
},
500: {
description: "A server error occurred.",
title: "Server Error",
},
title: "Error",
},
home: "Home",
id: "ID",
info: "Info",
navigation: {
filterPlaceholder: "Start typing to filter...",
filterTitle: "Filter",
tags: "Tags",
},
no: "No",
orderBy: {
asc: "Switch to ascending order",
desc: "Switch to descending order",
title: "Order by",
},
pagination: {
next: "Next page",
previous: "Previous page",
},
recipe: {
aggregateRating: "Foreign rating",
aggregateRatingCount: "Number of foreign ratings",
aggregateRatingValue: "Foreign rating",
clearAllTags: "Clear all",
cookTime: "Cook time",
cookedCount: "Cooked count",
createSuccessful: "The Recipe has been created successfully.",
deleteConfirmation: "Are you sure you want to delete this Recipe?",
deleteSuccessful: "The Recipe has been deleted successfully.",
editSuccessful: "The Recipe has been edited successfully.",
form: {
createIngredient: "Create Ingredient",
createInstruction: "Create Instruction",
deleteThumbnail: "Delete thumbnail",
group: {
basic: "Basic",
nutrition: "Nutrition",
ratings: "Ratings",
times: "Times",
},
imageError: "Please make sure you select an image.",
thumbnailHint: "You may click or drag and drop an image here.",
timeHint: "Time in seconds.",
},
import: {
alert: "The URLs have been processed. Please find the results below.",
result: "Result",
sourceUrl: "Source URL",
title: "Import",
urlInfo: "One URL per line.",
urls: "URLs",
},
ingredients: {
step: (step) => `Step ${step}`,
title: "Ingredients",
},
instructions: "Instructions",
lastCooked: (distance) => `Last cooked ${distance}.`,
lastCookedAt: "Last cooked at",
noRecipesFound:
"No recipes have been found for the current filter. Please change the filter options or add some more recipes.",
notCookedYet: "Not cooked yet.",
nutrition: {
calories: "Calories",
carbohydrate: "Carbohydrate",
cholesterol: "Cholesterol",
fat: "Fat",
fiber: "Fiber",
protein: "Protein",
saturatedFat: "Saturated Fat",
sodium: "Sodium",
sugar: "Sugar",
transFat: "Trans Fat",
unsaturatedFat: "Unsaturated Fat",
},
open: "Open",
orderBy: "Order by",
portions: "Portions",
prepTime: "Prep time",
rating: "Rating",
reviews: "Reviews",
source: "Source",
time: {
cook: "Cook time",
prep: "Prep time",
total: "Total time",
},
totalTime: "Total time",
yield: "Yield",
},
recipes: "Recipes",
save: "Save",
search: "Search",
title: "Title",
up: "Up",
updatedAt: "Updated",
yes: "Yes",
} as const;
Loading

0 comments on commit 233e869

Please sign in to comment.