From 594b976ad1a4f3df984070f7e5a97e9a169aab12 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 6 Jun 2021 15:36:56 +0200 Subject: [PATCH] Added support for chinese language. --- backend/i18n/source/backend_it.json | 2 -- backend/i18n/source/backend_nl.json | 1 - backend/i18n/source/backend_zh.json | 4 --- backend/i18n/source/frontend_it.json | 8 ----- backend/i18n/source/frontend_nl.json | 8 ----- .../translator/Squidex.Translator/Commands.cs | 28 ++++++++++++--- .../Squidex.Translator/Processes/Helper.cs | 35 ++++++++++++++++--- .../src/Squidex/Config/Web/WebExtensions.cs | 2 +- frontend/app/framework/utils/cookies.ts | 6 ++++ frontend/app/framework/utils/date-helper.ts | 9 +++-- frontend/app/shared/state/ui-languages.ts | 3 ++ .../internal/profile-menu.component.html | 10 +++--- .../pages/internal/profile-menu.component.ts | 14 ++++++-- 13 files changed, 88 insertions(+), 42 deletions(-) diff --git a/backend/i18n/source/backend_it.json b/backend/i18n/source/backend_it.json index 79cf41986..e8a7f0942 100644 --- a/backend/i18n/source/backend_it.json +++ b/backend/i18n/source/backend_it.json @@ -115,7 +115,6 @@ "common.success": "Successo", "common.text": "Testo", "common.trigger": "Trigger", - "common.url": "URL", "common.warning": "Warning", "common.workflow": "Workflow", "common.workflowStep": "Step", @@ -171,7 +170,6 @@ "contents.validation.normalCharactersBetween": "Deve essere un testo tra {min} e {max} carattere(i).", "contents.validation.notAllowed": "Non è un valore consentito.", "contents.validation.pattern": "Deve seguire il pattern.", - "contents.validation.reference": "La geolocalizzazione può avere come campi solamente come latitudine e longitudine.", "contents.validation.referenceNotFound": "Contiene un collegamento '{id}' non valido.", "contents.validation.referenceToInvalidSchema": "Contiene dei collegamenti '{id}' ad uno schema errato.", "contents.validation.regexTooSlow": "La regular expression è troppo lenta.", diff --git a/backend/i18n/source/backend_nl.json b/backend/i18n/source/backend_nl.json index 722021f95..39161207f 100644 --- a/backend/i18n/source/backend_nl.json +++ b/backend/i18n/source/backend_nl.json @@ -112,7 +112,6 @@ "common.signup": "Aanmelden", "common.text": "Tekst", "common.trigger": "Trigger", - "common.url": "URL", "common.workflow": "Workflow", "common.workflowStep": "Stap", "common.workflowTransition": "Overgang", diff --git a/backend/i18n/source/backend_zh.json b/backend/i18n/source/backend_zh.json index 2c26e0a9b..adfb0f506 100644 --- a/backend/i18n/source/backend_zh.json +++ b/backend/i18n/source/backend_zh.json @@ -250,13 +250,9 @@ "schemas.dateTimeCalculatedDefaultAndDefaultError": "计算出的默认值和默认值不能一起使用。", "schemas.duplicateFieldName": "字段 '{field}' 已添加两次。", "schemas.fieldCannotBeUIField": "字段不能是 UI 字段。", - "schema.fieldIsLocked": "Schema字段被锁定。", "schemas.fieldNameAlreadyExists": "已存在同名字段。", - "schema.fieldNotInSchema": "字段不是Schema的一部分。", "schemas.fieldsNotCovered": "字段 ID 未涵盖所有字段。", "schemas.nameAlreadyExists": "一个同名的Schema已经存在。", - "schema.noPermission": "您没有此Schema的权限。", - "schema.notFoundId": "Schema {id} 不存在。", "schemas.number.inlineEditorError": "无线电编辑器不允许内联编辑。", "schemas.onlyArraysHaveNested": "只有数组字段可以有嵌套字段。", "schemas.onylArraysInRoot": "嵌套字段不能是数组字段。", diff --git a/backend/i18n/source/frontend_it.json b/backend/i18n/source/frontend_it.json index 902d4767a..54b955dba 100644 --- a/backend/i18n/source/frontend_it.json +++ b/backend/i18n/source/frontend_it.json @@ -588,7 +588,6 @@ "roles.revokeFailed": "Non è stato possibile rimuovere il ruolo. Per favore ricarica.", "roles.roleNamePlaceholder": "Inserisci il nome del ruolo", "roles.updateFailed": "Non è stato possibile aggiornare il ruolo. Per favore ricarica.", - "rules.actionEdit": "Modifica l'Azione", "rules.cancelFailed": "Non è stato possibile eliminare la regola. Per favore ricarica.", "rules.create": "Crea un nuova Regola", "rules.createFailed": "Non è stato possibile creare una nuova regola. Per favore ricarica.", @@ -596,10 +595,8 @@ "rules.deleteConfirmText": "Sei sicuro di voler eliminare la regola?", "rules.deleteConfirmTitle": "Cancella la regola", "rules.deleteFailed": "Non è stato possibile eliminare la regola. Per favore ricarica.", - "rules.disableFailed": "Non è stato possibile disabilitare la regola. Per favore ricarica.", "rules.empty": "Nessuna regola è stato ancora creata.", "rules.emptyAddRule": "Aggiungi una regola", - "rules.enableFailed": "Non è stato possibile abilitare la regola. Per favore ricarica.", "rules.enqueued": "La regola è stata aggiunta alle code.", "rules.listPageTitle": "Regole", "rules.loadFailed": "Non è stato possibile caricare le regole. Per favore ricarica.", @@ -629,14 +626,9 @@ "rules.stop": "La regola si fermerà al più presto.", "rules.triggerConfirmText": "Sei sicuro che voler attivare la regola?", "rules.triggerConfirmTitle": "Attiva la regola", - "rules.triggerEdit": "Modifica l'Attivazione", "rules.triggerFailed": "Non è stato possibile attivare la regola. Per favore ricarica.", "rules.unnamed": "Regola senza nome", "rules.updateFailed": "Non è stato possibile aggiornare la regola. Per favore ricarica.", - "rules.wizard.actionHint": "La selezione del tipo di azione non potrà essere modificata successivamente.", - "rules.wizard.selectAction": "Seleziona l'Azione", - "rules.wizard.selectTrigger": "Seleziona l'Attivazione", - "rules.wizard.triggerHint": "La selezione del tipo di attivazione non potrà essere modificata successivamente.", "schemas.addField": "Aggiungi un Campo", "schemas.addFieldAndClose": "Crea e chiudi", "schemas.addFieldAndCreate": "Crea e aggiungi il campo", diff --git a/backend/i18n/source/frontend_nl.json b/backend/i18n/source/frontend_nl.json index 8a1b57ebf..00c21802c 100644 --- a/backend/i18n/source/frontend_nl.json +++ b/backend/i18n/source/frontend_nl.json @@ -560,7 +560,6 @@ "roles.revokeFailed": "Kan rol niet intrekken. Laad opnieuw.", "roles.roleNamePlaceholder": "Voer de rolnaam in", "roles.updateFailed": "Update rol mislukt. Laad opnieuw.", - "rules.actionEdit": "Bewerk actie", "rules.cancelFailed": "Annuleren van regel is mislukt. Laad opnieuw.", "rules.create": "Maak een nieuwe regel", "rules.createFailed": "Maken van regel is mislukt. Laad opnieuw.", @@ -568,10 +567,8 @@ "rules.deleteConfirmText": "Wil je de regel echt verwijderen?", "rules.deleteConfirmTitle": "Regel verwijderen", "rules.deleteFailed": "Verwijderen van regel is mislukt. Laad opnieuw.", - "rules.disableFailed": "Kan regel niet uitschakelen. Laad opnieuw.", "rules.empty": "Nog geen regel aangemaakt.", "rules.emptyAddRule": "Regel toevoegen", - "rules.enableFailed": "Kan regel niet inschakelen. Laad opnieuw.", "rules.enqueued": "Regel is toegevoegd aan de wachtrij.", "rules.listPageTitle": "Regels", "rules.loadFailed": "Laden van regels is mislukt. Laad opnieuw.", @@ -600,14 +597,9 @@ "rules.stop": "Regel stopt binnenkort.", "rules.triggerConfirmText": "Wil je echt de regel activeren?", "rules.triggerConfirmTitle": "Trigger regel", - "rules.triggerEdit": "Trigger bewerken", "rules.triggerFailed": "Kan regel niet activeren. Laad opnieuw.", "rules.unnamed": "Naamloos regel", "rules.updateFailed": "Update regel mislukt. Laad opnieuw.", - "rules.wizard.actionHint": "De selectie van het actietype kan later niet worden gewijzigd.", - "rules.wizard.selectAction": "Selecteer actie", - "rules.wizard.selectTrigger": "Selecteer Trigger", - "rules.wizard.triggerHint": "De selectie van het triggertype kan later niet worden gewijzigd.", "schemas.addField": "Veld toevoegen", "schemas.addFieldAndClose": "Maken en sluiten", "schemas.addFieldAndCreate": "Maak en voeg veld toe", diff --git a/backend/i18n/translator/Squidex.Translator/Commands.cs b/backend/i18n/translator/Squidex.Translator/Commands.cs index 64ea32a9d..4a6425a75 100644 --- a/backend/i18n/translator/Squidex.Translator/Commands.cs +++ b/backend/i18n/translator/Squidex.Translator/Commands.cs @@ -89,6 +89,26 @@ namespace Squidex.Translator new GenerateFrontendResources(folder, service).Run(); } + [Command(Name = "clean-backend", Description = "Clean the backend translations.")] + public void CleanBackend(TranslateArguments arguments) + { + var (folder, service) = Setup(arguments, "backend"); + + Helper.CleanOtherLocales(service); + + service.Save(); + } + + [Command(Name = "clean-frontend", Description = "Clean the frontend translations.")] + public void CleanFrontend(TranslateArguments arguments) + { + var (folder, service) = Setup(arguments, "frontend"); + + Helper.CleanOtherLocales(service); + + service.Save(); + } + [Command(Name = "gen-keys", Description = "Generate the keys for translations.")] public void GenerateBackendKeys(TranslateArguments arguments) { @@ -124,18 +144,18 @@ namespace Squidex.Translator throw new ArgumentException("Folder does not exist."); } - var supportedLocaled = new string[] { "en", "nl", "it" }; + var supportedLocales = new string[] { "en", "nl", "it", "zh" }; - var locales = supportedLocaled; + var locales = supportedLocales; if (arguments.Locales != null && arguments.Locales.Any()) { - locales = supportedLocaled.Intersect(arguments.Locales).ToArray(); + locales = supportedLocales.Intersect(arguments.Locales).ToArray(); } if (locales.Length == 0) { - locales = supportedLocaled; + locales = supportedLocales; } var translationsDirectory = new DirectoryInfo(Path.Combine(arguments.Folder, "backend", "i18n")); diff --git a/backend/i18n/translator/Squidex.Translator/Processes/Helper.cs b/backend/i18n/translator/Squidex.Translator/Processes/Helper.cs index 7eaa2b191..97612fc8a 100644 --- a/backend/i18n/translator/Squidex.Translator/Processes/Helper.cs +++ b/backend/i18n/translator/Squidex.Translator/Processes/Helper.cs @@ -30,9 +30,9 @@ namespace Squidex.Translator.Processes Console.WriteLine("----- CHECKING <{0}> -----", locale); var notTranslated = mainTranslations.Keys.Except(texts.Keys).ToList(); - var notRequired = texts.Keys.Except(mainTranslations.Keys).ToList(); + var notUsed = texts.Keys.Except(mainTranslations.Keys).ToList(); - if (notTranslated.Count > 0 || notRequired.Count > 0) + if (notTranslated.Count > 0 || notUsed.Count > 0) { if (notTranslated.Count > 0) { @@ -46,12 +46,12 @@ namespace Squidex.Translator.Processes } } - if (notRequired.Count > 0) + if (notUsed.Count > 0) { Console.WriteLine(); Console.WriteLine("Translations not used:"); - foreach (var key in notRequired.OrderBy(x => x)) + foreach (var key in notUsed.OrderBy(x => x)) { Console.Write(" * "); Console.WriteLine(key); @@ -65,6 +65,33 @@ namespace Squidex.Translator.Processes } } + public static void CleanOtherLocales(TranslationService service) + { + var mainTranslations = service.MainTranslations; + + foreach (var (locale, texts) in service.Translations.Where(x => x.Key != service.MainLocale)) + { + Console.WriteLine(); + Console.WriteLine("----- CLEANING <{0}> -----", locale); + + var notUsed = texts.Keys.Except(mainTranslations.Keys).ToList(); + + if (notUsed.Count > 0) + { + foreach (var unused in notUsed) + { + texts.Remove(unused); + } + + Console.WriteLine("Cleaned {0} translations.", notUsed.Count); + } + else + { + Console.WriteLine("> No errors found"); + } + } + } + public static void CheckUnused(TranslationService service, HashSet translations) { var notUsed = new SortedSet(); diff --git a/backend/src/Squidex/Config/Web/WebExtensions.cs b/backend/src/Squidex/Config/Web/WebExtensions.cs index 7308e27ed..5eeece8ca 100644 --- a/backend/src/Squidex/Config/Web/WebExtensions.cs +++ b/backend/src/Squidex/Config/Web/WebExtensions.cs @@ -39,7 +39,7 @@ namespace Squidex.Config.Web public static IApplicationBuilder UseSquidexLocalization(this IApplicationBuilder app) { - var supportedCultures = new[] { "en", "nl", "it" }; + var supportedCultures = new[] { "en", "nl", "it", "zh" }; var localizationOptions = new RequestLocalizationOptions() .SetDefaultCulture(supportedCultures[0]) diff --git a/frontend/app/framework/utils/cookies.ts b/frontend/app/framework/utils/cookies.ts index e1681a508..b23adf381 100644 --- a/frontend/app/framework/utils/cookies.ts +++ b/frontend/app/framework/utils/cookies.ts @@ -20,6 +20,12 @@ export module Cookies { document.cookie = `${name}=${value || ''}${expires}; path=/`; } + export function replace(name: string, value: string, days: number) { + remove(name); + + set(name, value, days); + } + export function remove(name: string) { document.cookie = `${name}=; Max-Age=-99999999;`; } diff --git a/frontend/app/framework/utils/date-helper.ts b/frontend/app/framework/utils/date-helper.ts index 64a0c72c2..b52459b73 100644 --- a/frontend/app/framework/utils/date-helper.ts +++ b/frontend/app/framework/utils/date-helper.ts @@ -5,12 +5,17 @@ * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. */ -import { enUS, it, nl } from 'date-fns/locale'; +import { enUS, it, nl, zhCN } from 'date-fns/locale'; export module DateHelper { let locale: string | null; - export const FNSLOCALES = { enUS, it, nl }; + export const FNSLOCALES = { + en: enUS, + it, + nl, + zh: zhCN, + }; export function setlocale(code: string | null) { locale = code; diff --git a/frontend/app/shared/state/ui-languages.ts b/frontend/app/shared/state/ui-languages.ts index 0835e40f4..d6dbf9a10 100644 --- a/frontend/app/shared/state/ui-languages.ts +++ b/frontend/app/shared/state/ui-languages.ts @@ -17,5 +17,8 @@ export module UILanguages { }, { iso2Code: 'it', localName: 'Italiano', + }, { + iso2Code: 'zh', + localName: '中国人', }]; } diff --git a/frontend/app/shell/pages/internal/profile-menu.component.html b/frontend/app/shell/pages/internal/profile-menu.component.html index 9dc28002b..f2471456d 100644 --- a/frontend/app/shell/pages/internal/profile-menu.component.html +++ b/frontend/app/shell/pages/internal/profile-menu.component.html @@ -5,7 +5,7 @@ - +