Skip to content

Commit

Permalink
feat: update localization to receive and apply locale changes from co…
Browse files Browse the repository at this point in the history
…re-registery
  • Loading branch information
shahmeerzaidi committed Jul 10, 2024
1 parent 21a3484 commit 029948b
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AppNavigator } from './navigation';
import theme from './theme';

import { IndeterminateProgressOverlay } from './components';
import { LocaleChangeListener } from './components/blocks/LocaleChangeListener';

const App = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -46,6 +47,7 @@ const App = () => {
defaultLocale="en"
messages={translationTokens.default}
>
<LocaleChangeListener />
<AppNavigator />
</IntlProvider>
</ThemeProvider>
Expand Down
29 changes: 29 additions & 0 deletions src/components/blocks/LocaleChangeListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { setLocale } from '../../store/actions/appActions';

const LocaleChangeListener = () => {
const dispatch = useDispatch();

useEffect(() => {
// Function to handle the message event
const handleMessage = event => {
if (event?.data?.changeLocale) {
dispatch(setLocale(event?.data?.changeLocale));
}
};

// Add the event listener
window.addEventListener('message', handleMessage, false);

// Return a function that will be called when the component unmounts
return () => {
// Remove the event listener
window.removeEventListener('message', handleMessage, false);
};
}, []);

return <></>;
};

export { LocaleChangeListener };
18 changes: 17 additions & 1 deletion src/translations/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import * as en from './tokens/en-US.json';
import * as es from './tokens/es.json';
import * as fr from './tokens/fr.json';
import * as de from './tokens/de.json';
import * as cn from './tokens/zh-cn.json';

const LANGUAGE_CODES = Object.freeze({
ENGLISH: 'en-US',
PAK: 'pk-PK',
SPANISH: 'es-ES',
FRENCH: 'fr-FR',
GERMAN: 'de-DE',
CHINESE: 'cn',
});

const loadLocaleData = locale => {
switch (locale) {
case LANGUAGE_CODES.ENGLISH_US:
case LANGUAGE_CODES.SPANISH:
return es;
case LANGUAGE_CODES.FRENCH:
return fr;
case LANGUAGE_CODES.GERMAN:
return de;
case LANGUAGE_CODES.CHINESE:
return cn;
case LANGUAGE_CODES.ENGLISH:
default:
return en;
Expand Down
68 changes: 68 additions & 0 deletions src/translations/tokens/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"carbon-tokenization-engine": "Kohlenstoff -Tokenisierung Motor",
"quantity-of-credits": "Menge an Credits",
"detokenized-units": "Detekizierte Einheiten",
"detokenize": "Detokenize",
"project-id": "Projekt ID",
"project-name": "Projektname",
"upload": "Hochladen",
"file-upload": "Datei-Upload",
"password": "Passwort",
"vintage": "Jahrgang",
"project-link": "Projektlink",
"unit-owner": "Einheitenbesitzer",
"unit-block-start": "Einheitsblockstart",
"unit-block-end": "Einheit Blockende",
"quantity": "Menge",
"account-holder-wallet-address": "Account Inhaber Brieftaschenadresse",
"existing-marketplace-identifier": "Bestehende Marktkennungen",
"connect-to-cw": "Verbinden",
"connect": "Verbinden",
"server-address": "Serveradresse",
"api-key": "API-Schlüssel",
"storybook": "Storybook",
"hello-world": "Willkommen bei Carbon Tokenization Engine",
"ok": "OK",
"search": "Suchen",
"select": "Wählen",
"filters": "Filter",
"network-error": "Netzwerkfehler",
"there-is-a-connection-error": "Es gibt einen Verbindungsfehler",
"something-went-wrong": "Hoppla! Etwas ist schiefgelaufen",
"success": "Erfolg",
"connected": "In Verbindung gebracht",
"disconnect": "Trennen",
"create-tokens": "Token erstellen",
"create-token": "Token erstellen",
"revert-tokens": "Token zurückkehren",
"existing-tokens": "Tokenisierte Einheiten",
"no-existing-tokens": "Es gibt keine tokenisierten Einheiten.",
"untokenized-units": "Untokenisierte Einheiten",
"org-uid": "Org uid",
"add-valid-server-address": "Fügen Sie eine gültige Serveradresse hinzu",
"add-valid-api-key": "Fügen Sie einen gültigen API -Schlüssel hinzu",
"untokenized-units-not-loaded": "Untokenisierte Einheiten konnten nicht geladen werden.",
"tokens-not-loaded": "Token konnten nicht geladen werden.",
"projects-not-loaded": "Projekte konnten nicht geladen werden.",
"no-untokenized-units": "Es gibt keine unhöflichen Einheiten.",
"actions": "Aktionen",
"unit-was-tokenized": "Einheiten -Tokenisierungsprozess begann.Bitte gehen Sie in 5 Minuten zurück.",
"unit-not-tokenized": "Die Einheit konnte nicht tokenisiert werden.",
"projectLink": "Projektlink",
"cancel": "Stornieren",
"token-creation-pending": "Token -Kreation anhängig",
"detok-file-parsed": "Die Detok -Datei wurde erfolgreich analysiert.",
"detok-file-not-parsed": "Entdeckung konnte nicht analysiert werden.",
"add-valid-detok-file": "Fügen Sie eine gültige Detok -Datei hinzu.",
"add-valid-detok-password": "Fügen Sie gültiges Detok -Passwort hinzu.",
"update": "Aktualisieren",
"import": "Importieren",
"import-home-org": "Home importieren",
"connect-to-remote": "Verbindung zu Fern eine Verbindung hergestellt",
"update-home-org": "Home Update",
"detokanization-successful": "Die Einheit wurde erfolgreich festgestellt.",
"detokanization-not-successful": "Die Einheit konnte nicht festgestellt werden.",
"confirm-detokanization": "Bestätigen Sie die Entdeckung der Einheit",
"confirm": "Bestätigen",
"detok-file-archive-not-valid": "Die Detok -Datei konnte nicht aus dem Archiv erhalten werden."
}
68 changes: 68 additions & 0 deletions src/translations/tokens/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"carbon-tokenization-engine": "Motor de tokenización de carbono",
"quantity-of-credits": "Cantidad de créditos",
"detokenized-units": "Unidades retiradas",
"detokenize": "Retrokenizar",
"project-id": "Projecto ID",
"project-name": "Nombre del proyecto",
"upload": "Subir",
"file-upload": "Subir archivo",
"password": "Contraseña",
"vintage": "Vintage",
"project-link": "Enlace de proyecto",
"unit-owner": "Propietario de la unidad",
"unit-block-start": "Inicio del bloque de la unidad",
"unit-block-end": "Extremo de bloque de unidades",
"quantity": "Cantidad",
"account-holder-wallet-address": "Dirección de billetera del titular de la cuenta",
"existing-marketplace-identifier": "Identificadores del mercado existentes",
"connect-to-cw": "Conectar",
"connect": "Conectar",
"server-address": "Dirección del servidor",
"api-key": "Clave API",
"storybook": "Libro de cuentos",
"hello-world": "Bienvenido al motor de tokenización de carbono",
"ok": "De acuerdo",
"search": "Buscar",
"select": "Seleccionar",
"filters": "Filtros",
"network-error": "Error de red",
"there-is-a-connection-error": "Hay un error de conexión",
"something-went-wrong": "Huy! Algo salió mal",
"success": "Éxito",
"connected": "Connected",
"disconnect": "Desconectar",
"create-tokens": "Crear tokens",
"create-token": "Crear token",
"revert-tokens": "Revertir tokens",
"existing-tokens": "Unidades tokenizadas",
"no-existing-tokens": "No hay unidades tokenizadas.",
"untokenized-units": "Unidades no liberadas",
"org-uid": "Org uid",
"add-valid-server-address": "Agregar una dirección de servidor válida",
"add-valid-api-key": "Agregar una clave API válida",
"untokenized-units-not-loaded": "Las unidades no liberadas no se pueden cargar.",
"tokens-not-loaded": "Los tokens no se podían cargar.",
"projects-not-loaded": "Los proyectos no se pueden cargar.",
"no-untokenized-units": "No hay unidades no liberadas.",
"actions": "Comportamiento",
"unit-was-tokenized": "Se inició el proceso de tokenización de la unidad.Vuelve en 5 minutos.",
"unit-not-tokenized": "La unidad no pudo ser tokenizada.",
"projectLink": "Enlace de proyecto",
"cancel": "Cancelar",
"token-creation-pending": "Creación de token pendiente",
"detok-file-parsed": "El archivo de Detok se analizó con éxito.",
"detok-file-not-parsed": "Detok no pudo ser analizado.",
"add-valid-detok-file": "Agregue un archivo de desvío válido.",
"add-valid-detok-password": "Agregue una contraseña de desvío válida.",
"update": "Actualizar",
"import": "Importar",
"import-home-org": "Importar en casa",
"connect-to-remote": "Conectarse a remoto",
"update-home-org": "Actualización de inicio",
"detokanization-successful": "La unidad fue contenida con éxito.",
"detokanization-not-successful": "La unidad no se pudo ser contenida.",
"confirm-detokanization": "Confirmar la desocanización de la unidad",
"confirm": "Confirmar",
"detok-file-archive-not-valid": "El archivo Detok no se pudo obtener del archivo."
}
68 changes: 68 additions & 0 deletions src/translations/tokens/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"carbon-tokenization-engine": "Moteur de jeton de carbone",
"quantity-of-credits": "Quantité de crédits",
"detokenized-units": "Unités détochéisées",
"detokenize": "Se détacher",
"project-id": "ID du projet",
"project-name": "nom du projet",
"upload": "Télécharger",
"file-upload": "Téléchargement de fichiers",
"password": "Mot de passe",
"vintage": "Vintage",
"project-link": "Lien de projet",
"unit-owner": "Propriétaire de l'unité",
"unit-block-start": "Démarrage du bloc d'unité",
"unit-block-end": "Fin du bloc d'unité",
"quantity": "Quantité",
"account-holder-wallet-address": "Adresse du portefeuille du support de compte",
"existing-marketplace-identifier": "Identificateurs de marché existants",
"connect-to-cw": "Connecter",
"connect": "Connecter",
"server-address": "Adresse du serveur",
"api-key": "Clé API",
"storybook": "Livre de contes",
"hello-world": "Bienvenue sur le moteur de tokenisation en carbone",
"ok": "D'accord",
"search": "Recherche",
"select": "Sélectionner",
"filters": "Filtres",
"network-error": "Erreur de réseau",
"there-is-a-connection-error": "Il y a une erreur de connexion",
"something-went-wrong": "Oups, quelque chose s'est mal passé",
"success": "Succès",
"connected": "Connecté",
"disconnect": "Débrancher",
"create-tokens": "Créer des jetons",
"create-token": "Créer un jeton",
"revert-tokens": "Retourner les jetons",
"existing-tokens": "Unités tokenisées",
"no-existing-tokens": "Il n'y a pas d'unités tokenisées.",
"untokenized-units": "Unités non contournées",
"org-uid": "Org uid",
"add-valid-server-address": "Ajouter une adresse de serveur valide",
"add-valid-api-key": "Ajouter une clé API valide",
"untokenized-units-not-loaded": "Les unités non suspendues ne pouvaient pas être chargées.",
"tokens-not-loaded": "Les jetons n'ont pas pu être chargés.",
"projects-not-loaded": "Les projets n'ont pas pu être chargés.",
"no-untokenized-units": "Il n'y a pas d'unités non suspendues.",
"actions": "Actions",
"unit-was-tokenized": "Le processus de jeton de l'unité a commencé.Veuillez revenir en 5 minutes.",
"unit-not-tokenized": "L'unité ne pouvait pas être tokenisée.",
"projectLink": "Lien de projet",
"cancel": "Annuler",
"token-creation-pending": "Création de jetons en attente",
"detok-file-parsed": "Le fichier detok a été analysé avec succès.",
"detok-file-not-parsed": "Detok ne pouvait pas être analysé.",
"add-valid-detok-file": "Ajoutez un fichier detok valide.",
"add-valid-detok-password": "Ajoutez un mot de passe Detok valide.",
"update": "Mise à jour",
"import": "Importer",
"import-home-org": "Importer à la maison",
"connect-to-remote": "Connectez-vous à la distance",
"update-home-org": "Mise à jour domestique",
"detokanization-successful": "L'unité a été détanklée avec succès.",
"detokanization-not-successful": "L'unité n'a pas pu être détokezedisée.",
"confirm-detokanization": "Confirmer la détokanisation de l'unité",
"confirm": "Confirmer",
"detok-file-archive-not-valid": "Le fichier detok n'a pas pu être obtenu à partir d'archives."
}
68 changes: 68 additions & 0 deletions src/translations/tokens/zh-cn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"carbon-tokenization-engine": "碳令牌化引擎",
"quantity-of-credits": "数量的学分",
"detokenized-units": "偏发单位",
"detokenize": "陈旧",
"project-id": "项目ID",
"project-name": "项目名",
"upload": "上传",
"file-upload": "上传文件",
"password": "密码",
"vintage": "优质的",
"project-link": "项目链接",
"unit-owner": "单位所有者",
"unit-block-start": "单位块启动",
"unit-block-end": "单位块端",
"quantity": "数量",
"account-holder-wallet-address": "帐户持有人钱包地址",
"existing-marketplace-identifier": "现有的市场标识符",
"connect-to-cw": "连接",
"connect": "连接",
"server-address": "服务器地址",
"api-key": "API键",
"storybook": "故事书",
"hello-world": "欢迎来到碳令牌化引擎",
"ok": "好的",
"search": "搜索",
"select": "选择",
"filters": "过滤器",
"network-error": "网络错误",
"there-is-a-connection-error": "有连接错误",
"something-went-wrong": "哎呀!出事了",
"success": "成功",
"connected": "连接的",
"disconnect": "断开",
"create-tokens": "创建令牌",
"create-token": "创建令牌",
"revert-tokens": "恢复令牌",
"existing-tokens": "令牌单元",
"no-existing-tokens": "没有象征性的单元。",
"untokenized-units": "未使用的单位",
"org-uid": "org uid",
"add-valid-server-address": "添加有效的服务器地址",
"add-valid-api-key": "添加有效的API密钥",
"untokenized-units-not-loaded": "无法加载未使用的单元。",
"tokens-not-loaded": "代币无法加载。",
"projects-not-loaded": "项目无法加载。",
"no-untokenized-units": "没有未使用的单元。",
"actions": "动作",
"unit-was-tokenized": "单位令牌化过程开始了。请在5分钟内回来。",
"unit-not-tokenized": "单位不能被象征化。",
"projectLink": "项目链接",
"cancel": "取消",
"token-creation-pending": "代币创建待定",
"detok-file-parsed": "DITOK文件已成功解析。",
"detok-file-not-parsed": "无法解析毒。",
"add-valid-detok-file": "添加有效的降水文件。",
"add-valid-detok-password": "添加有效的DITOK密码。",
"update": "更新",
"import": "进口",
"import-home-org": "进口房屋",
"connect-to-remote": "连接到遥控器",
"update-home-org": "家庭更新",
"detokanization-successful": "单位被成功地爆发了。",
"detokanization-not-successful": "单位不能被打印。",
"confirm-detokanization": "确认单位变形",
"confirm": "确认",
"detok-file-archive-not-valid": "无法从档案中获得毒文件。"
}

0 comments on commit 029948b

Please sign in to comment.