i18n - Multiple languages overrides
This commit is contained in:
1 parent
1874f93bcc
commit
236a115112
33 files changed
+1401
-695
No files matched your search
@@ -1,70 +0,0 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
const currentLanguage = process.env.APP_LANG || 'en-US';
|
||||
|
||||
function getDefaultLanguage() {
|
||||
const mainLanguage = currentLanguage.match(/(.*.)(-)/);
|
||||
return mainLanguage !== null ? mainLanguage[1] : null;
|
||||
}
|
||||
|
||||
function getCleanKeyForNameSpaces(key) {
|
||||
const regexKeyCleaner = new RegExp(
|
||||
`^(\\.\\/${currentLanguage}\\/)(.*.)(\\.json)$`
|
||||
);
|
||||
const cleanedKey = key.match(regexKeyCleaner);
|
||||
return cleanedKey !== null ? cleanedKey[2] : null;
|
||||
}
|
||||
|
||||
function getCleanKeyForDefaults(key) {
|
||||
const regexKeyCleaner = new RegExp(
|
||||
`^(\\.\\/${getDefaultLanguage()}\\/)(.*.)(\\.json)$`
|
||||
);
|
||||
const cleanedKey = key.match(regexKeyCleaner);
|
||||
return cleanedKey !== null ? cleanedKey[2] : null;
|
||||
}
|
||||
|
||||
function getLocales() {
|
||||
const currentLangList = {};
|
||||
const defaultLangList = {};
|
||||
const locales = {};
|
||||
const context = require.context(`./locales`, true, /\.json$/);
|
||||
|
||||
context.keys().forEach(key => {
|
||||
const isTheSameOfCurrentLang = key.indexOf(currentLanguage) >= 0;
|
||||
const isADefaultLang = key.indexOf(`${getDefaultLanguage()}/`) >= 0;
|
||||
|
||||
if (isTheSameOfCurrentLang) {
|
||||
currentLangList[getCleanKeyForNameSpaces(key)] = context(key);
|
||||
}
|
||||
|
||||
if (isADefaultLang) {
|
||||
defaultLangList[getCleanKeyForDefaults(key)] = context(key);
|
||||
}
|
||||
});
|
||||
|
||||
locales[currentLanguage] = { ...currentLangList };
|
||||
locales[getDefaultLanguage()] = { ...defaultLangList };
|
||||
return locales;
|
||||
}
|
||||
|
||||
// console.log(getLocales(), currentLanguage, getDefaultLanguage());
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
resources: getLocales(),
|
||||
fallbackLng: getDefaultLanguage(),
|
||||
lng: currentLanguage,
|
||||
debug: true,
|
||||
|
||||
// have a common namespace used around the full app
|
||||
keySeparator: false, // uses content as keys
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
|
||||
react: {
|
||||
wait: true,
|
||||
},
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Regular → Executable
+78
-1
@@ -1 +1,78 @@
|
||||
export { default } from './i18n';
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
|
||||
const currentLanguage = process.env.APP_LANG || 'en-US';
|
||||
const debugMode = process.env.I18N_DEBUG || false;
|
||||
|
||||
function getDefaultLanguage() {
|
||||
const mainLanguage = currentLanguage.match(/(.*.)(-)/);
|
||||
return mainLanguage !== null ? mainLanguage[1] : null;
|
||||
}
|
||||
|
||||
function getNameSpaceString(key) {
|
||||
const nameSpaceMatcher = key.match(/[^/]+$/g);
|
||||
let finalNameSpace;
|
||||
|
||||
if (nameSpaceMatcher !== null) {
|
||||
finalNameSpace = nameSpaceMatcher[0].replace('.json', '');
|
||||
}
|
||||
|
||||
return finalNameSpace;
|
||||
}
|
||||
|
||||
function getCleanKeyForNameSpaces(key) {
|
||||
const cleanedKey = key.match(/[/\\].+(?=[/\\])/);
|
||||
let finalKey;
|
||||
|
||||
if (cleanedKey !== null) {
|
||||
finalKey = cleanedKey[0].replace(/[/\\]/, '');
|
||||
finalKey = finalKey.replace(/[/\\]/, '-');
|
||||
}
|
||||
|
||||
return finalKey;
|
||||
}
|
||||
|
||||
function getLocales() {
|
||||
const context = require.context(`./locales`, true, /\.json$/);
|
||||
const locales = {};
|
||||
|
||||
context.keys().forEach(key => {
|
||||
locales[getCleanKeyForNameSpaces(key)] = {
|
||||
...locales[getCleanKeyForNameSpaces(key)],
|
||||
[getNameSpaceString(key)]: context(key),
|
||||
};
|
||||
});
|
||||
|
||||
return locales;
|
||||
}
|
||||
|
||||
let translate;
|
||||
|
||||
i18n
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources: getLocales(),
|
||||
fallbackLng: getDefaultLanguage(),
|
||||
|
||||
lng: currentLanguage,
|
||||
debug: debugMode,
|
||||
|
||||
// have a common namespace used around the full app
|
||||
keySeparator: false, // uses content as keys
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
|
||||
fallbackNS: ['common'],
|
||||
defaultNS: 'common',
|
||||
|
||||
react: {
|
||||
wait: true,
|
||||
},
|
||||
})
|
||||
.then(function(t) {
|
||||
translate = t;
|
||||
});
|
||||
|
||||
export { translate as t };
|
||||
export default i18n;
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"header_test": "Joao Grandao"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"common": {
|
||||
"Welcome to React": "Welcome to React and react-i18next",
|
||||
"welcomeMsg": "welcome"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"header_test": "$t(common:test)"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"tests___": "test common"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"Themes": "Themes",
|
||||
"Previous": "Previous",
|
||||
"Next": "Next",
|
||||
"Play": "Play",
|
||||
"Stop": "Stop",
|
||||
"Layout": "Layout",
|
||||
"More": "More",
|
||||
"Crosshairs": "Crosshairs",
|
||||
"Magnify": "Magnify",
|
||||
"ROI Window": "ROI Window",
|
||||
"Probe": "Probe",
|
||||
"Ellipse": "Ellipse",
|
||||
"Rectangle": "Rectangle",
|
||||
"Invert": "Invert",
|
||||
"Rotate Right": "Rotate Right",
|
||||
"Flip H": "Flip H",
|
||||
"Flip V": "Flip V",
|
||||
"Clear": "Clear",
|
||||
"Brush": "Brush",
|
||||
"Coronal": "Coronal",
|
||||
"Stack Scroll": "Stack Scroll",
|
||||
"Measurements": "Measurements",
|
||||
"Zoom": "Zoom",
|
||||
"Levels": "Levels",
|
||||
"Pan": "Pan",
|
||||
"Length": "Length",
|
||||
"Angle": "Angle",
|
||||
"Bidirectional": "Bidirectional",
|
||||
"Freehand": "Freehand",
|
||||
"EllipticalRoi": "EllipticalRoi",
|
||||
"CircleRoi": "CircleRoi",
|
||||
"RectangleRoi": "RectangleRoi",
|
||||
"Reset": "Reset",
|
||||
"CINE": "CINE",
|
||||
"Acquired": "Acquired",
|
||||
"Sagittal": "Sagittal",
|
||||
"Axial": "Axial"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"fps": "ingles fps",
|
||||
"Skip to first image": "Skip to first image",
|
||||
"Previous image": "Previous, image",
|
||||
"Play / Stop": "Play, / Stop",
|
||||
"Next image": "Next, image",
|
||||
"Skip to last image": "Skip, to last image",
|
||||
"Skip to first image": "Skip, to first image",
|
||||
"Previous image": "Previous, image",
|
||||
"Play / Stop": "Play, / Stop",
|
||||
"Next image": "Next, image",
|
||||
"Skip to last image": "Skip, to last image",
|
||||
"Skip to first image": "Skip, to first image",
|
||||
"Previous image": "Previous, image",
|
||||
"Play / Stop": "Play, / Stop",
|
||||
"Next image": "Next, image",
|
||||
"Skip to last image": "Skip, to last image"
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
{
|
||||
"header_test": "$t(common:test)"
|
||||
"preferences": "Preferences",
|
||||
"options": "Options",
|
||||
"about": "About",
|
||||
"back_to_viewer": "Back to Viewer",
|
||||
"study_list": "Study list",
|
||||
"research_use": "INVESTIGATIONAL USE ONLY"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"research_use": "INVESTIGATIONAL PURPOSES ONLY"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"options": "Erik Options",
|
||||
"about": "About"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"research_use": "SOLO USO DE DESAROLLO"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"Themes": "Temas",
|
||||
"Previous": "Anterior",
|
||||
"Next": "Próximo",
|
||||
"Play": "Play",
|
||||
"Stop": "Stop",
|
||||
"Layout": "Esquema",
|
||||
"More": "Más",
|
||||
"Crosshairs": "Cruces",
|
||||
"Magnify": "Lupa",
|
||||
"ROI Window": "Ventana ROI",
|
||||
"Probe": "Probar",
|
||||
"Ellipse": "Elipse",
|
||||
"Rectangle": "Rectángulo",
|
||||
"Invert": "Invertido",
|
||||
"Rotate Right": "Rotar ->",
|
||||
"Flip H": "Espejo Hor.",
|
||||
"Flip V": "Espejo Ver.",
|
||||
"Clear": "Limpiar",
|
||||
"Brush": "Escoba",
|
||||
"Coronal": "Coronal",
|
||||
"Stack Scroll": "Avance X slice",
|
||||
"Measurements": "Medidas",
|
||||
"Zoom": "Zoom",
|
||||
"Levels": "Niveles",
|
||||
"Pan": "Mover",
|
||||
"Length": "Medición",
|
||||
"Angle": "Ángulo",
|
||||
"Bidirectional": "Bidirectional",
|
||||
"Freehand": "Freehand",
|
||||
"EllipticalRoi": "EllipticalRoi",
|
||||
"CircleRoi": "CircleRoi",
|
||||
"RectangleRoi": "RectangleRoi",
|
||||
"Reset": "Reiniciar",
|
||||
"CINE": "CINE",
|
||||
"Acquired": "Acquired",
|
||||
"Sagittal": "Sagittal",
|
||||
"Axial": "Axial"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"fps": "fps",
|
||||
"Skip to first image": "Avanza para la primera imagen",
|
||||
"Previous image": "Imagen anterior",
|
||||
"Play / Stop": "Play / Stop",
|
||||
"Next image": "Próximo image",
|
||||
"Skip to last image": "Pular para la ultima imagen"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"research_use": "SOLO USO DE INVESTIGACIÓN",
|
||||
"options": "Opciones",
|
||||
"about": "Sobre",
|
||||
"preferences": "Preferencias",
|
||||
"study_list": "Lista de estudio"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"Opciones": "Elecciones"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"Themes": "Temas",
|
||||
"Previous": "Anterior",
|
||||
"Next": "Próximo",
|
||||
"Play": "Play",
|
||||
"Stop": "Stop",
|
||||
"Layout": "Esquema",
|
||||
"More": "Más",
|
||||
"Crosshairs": "Cruces",
|
||||
"Magnify": "Lupa",
|
||||
"ROI Window": "Ventana ROI",
|
||||
"Probe": "Probar",
|
||||
"Ellipse": "Elipse",
|
||||
"Rectangle": "Rectángulo",
|
||||
"Invert": "Invertido",
|
||||
"Rotate Right": "Rotar ->",
|
||||
"Flip H": "Espejo Hor.",
|
||||
"Flip V": "Espejo Ver.",
|
||||
"Clear": "Limpiar",
|
||||
"Brush": "Escoba"
|
||||
}
|
||||
Reference in new issue
Block a user