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,7 +1,7 @@
|
||||
{
|
||||
"name": "ohif-i18n",
|
||||
"version": "0.0.1",
|
||||
"description": "OHIF extension internationalization",
|
||||
"description": "OHIF extension for internationalization",
|
||||
"author": "OHIF",
|
||||
"license": "MIT",
|
||||
"repository": "OHIF/Viewers",
|
||||
@@ -17,8 +17,8 @@
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react-i18next": "^10.11.0",
|
||||
"i18next": "^15.1.3"
|
||||
"i18next": "^15.1.3",
|
||||
"react-i18next": "^10.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.2.2",
|
||||
@@ -40,6 +40,7 @@
|
||||
"rollup": "^1.1.2",
|
||||
"rollup-plugin-babel": "^4.2.0",
|
||||
"rollup-plugin-commonjs": "^9.2.0",
|
||||
"rollup-plugin-copy": "^2.0.1",
|
||||
"rollup-plugin-node-builtins": "^2.1.2",
|
||||
"rollup-plugin-node-resolve": "^4.0.0",
|
||||
"rollup-plugin-peer-deps-external": "^2.2.0",
|
||||
|
||||
@@ -7,6 +7,7 @@ import url from 'rollup-plugin-url'
|
||||
import pkg from './package.json'
|
||||
// Deal with https://github.com/rollup/rollup-plugin-commonjs/issues/297
|
||||
import builtins from 'rollup-plugin-node-builtins';
|
||||
import copy from 'rollup-plugin-copy'
|
||||
|
||||
const globals = {
|
||||
'react': 'React',
|
||||
@@ -39,6 +40,12 @@ export default {
|
||||
postcss({
|
||||
modules: false
|
||||
}),
|
||||
copy({
|
||||
targets: [
|
||||
'src/locales'
|
||||
],
|
||||
outputFolder: 'dist'
|
||||
}),
|
||||
url(),
|
||||
babel({
|
||||
exclude: 'node_modules/**',
|
||||
@@ -47,21 +54,7 @@ export default {
|
||||
}),
|
||||
resolve(),
|
||||
commonjs({
|
||||
include: ['node_modules/**', '.yalc/**'],
|
||||
namedExports: {
|
||||
'node_modules/react-vtkjs-viewport/dist/index.js': [
|
||||
'getImageData',
|
||||
'loadImageData',
|
||||
'VTKViewport',
|
||||
'VTKMPRViewport',
|
||||
],
|
||||
'.yalc/react-vtkjs-viewport/dist/index.js': [
|
||||
'getImageData',
|
||||
'loadImageData',
|
||||
'VTKViewport',
|
||||
'VTKMPRViewport',
|
||||
]
|
||||
}
|
||||
include: ['node_modules/**', '.yalc/**']
|
||||
})
|
||||
],
|
||||
external: Object.keys(pkg.peerDependencies || {}),
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
+1240
-24
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user