Merge branch 'feature/i18n-basics' of github.com:romulobordezani/Viewers into feature/i18n-basics
This commit is contained in:
commit
aff74bcee4
14
extensions/ohif-i18n/.babelrc
Normal file
14
extensions/ohif-i18n/.babelrc
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["@babel/preset-env", {
|
||||||
|
"targets": {
|
||||||
|
"ie": "11"
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
"@babel/preset-react"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
"@babel/plugin-transform-runtime"
|
||||||
|
]
|
||||||
|
}
|
||||||
9
extensions/ohif-i18n/.editorconfig
Normal file
9
extensions/ohif-i18n/.editorconfig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
26
extensions/ohif-i18n/.gitignore
vendored
Normal file
26
extensions/ohif-i18n/.gitignore
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# builds
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.idea
|
||||||
|
|
||||||
|
yalc.lock
|
||||||
|
.yalc
|
||||||
21
extensions/ohif-i18n/LICENSE
Normal file
21
extensions/ohif-i18n/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Open Health Imaging Foundation
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
73
extensions/ohif-i18n/package.json
Normal file
73
extensions/ohif-i18n/package.json
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"name": "ohif-i18n",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "OHIF extension internationalization",
|
||||||
|
"author": "OHIF",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": "OHIF/Viewers",
|
||||||
|
"main": "dist/index.umd.js",
|
||||||
|
"module": "dist/index.es.js",
|
||||||
|
"jsnext:main": "dist/index.es.js",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8",
|
||||||
|
"npm": ">=5"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react-i18next": "^10.11.0",
|
||||||
|
"i18next": "^15.1.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.2.2",
|
||||||
|
"@babel/plugin-external-helpers": "^7.2.0",
|
||||||
|
"@babel/plugin-proposal-class-properties": "^7.2.3",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.2.0",
|
||||||
|
"@babel/preset-env": "^7.2.3",
|
||||||
|
"@babel/preset-react": "^7.0.0",
|
||||||
|
"babel-eslint": "^10.0.1",
|
||||||
|
"cross-env": "^5.2.0",
|
||||||
|
"eslint": "5.13.0",
|
||||||
|
"eslint-plugin-import": "^2.14.0",
|
||||||
|
"eslint-plugin-node": "^8.0.0",
|
||||||
|
"eslint-plugin-promise": "^4.0.1",
|
||||||
|
"eslint-plugin-react": "^7.11.1",
|
||||||
|
"husky": "^1.3.1",
|
||||||
|
"lint-staged": "^8.1.0",
|
||||||
|
"prettier": "^1.15.3",
|
||||||
|
"rollup": "^1.1.2",
|
||||||
|
"rollup-plugin-babel": "^4.2.0",
|
||||||
|
"rollup-plugin-commonjs": "^9.2.0",
|
||||||
|
"rollup-plugin-node-builtins": "^2.1.2",
|
||||||
|
"rollup-plugin-node-resolve": "^4.0.0",
|
||||||
|
"rollup-plugin-peer-deps-external": "^2.2.0",
|
||||||
|
"rollup-plugin-postcss": "^2.0.3",
|
||||||
|
"rollup-plugin-url": "^2.1.0"
|
||||||
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "lint-staged"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"src/**/*.{js,jsx,json,css}": [
|
||||||
|
"prettier --single-quote --write",
|
||||||
|
"git add"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not ie <= 11",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.2.0",
|
||||||
|
"classnames": "^2.2.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
68
extensions/ohif-i18n/rollup.config.js
Normal file
68
extensions/ohif-i18n/rollup.config.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import babel from 'rollup-plugin-babel'
|
||||||
|
import commonjs from 'rollup-plugin-commonjs'
|
||||||
|
import external from 'rollup-plugin-peer-deps-external'
|
||||||
|
import postcss from 'rollup-plugin-postcss'
|
||||||
|
import resolve from 'rollup-plugin-node-resolve'
|
||||||
|
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';
|
||||||
|
|
||||||
|
const globals = {
|
||||||
|
'react': 'React',
|
||||||
|
'react-dom': 'ReactDOM',
|
||||||
|
'react-redux': 'ReactRedux',
|
||||||
|
'react-resize-detector': 'ReactResizeDetector',
|
||||||
|
'prop-types': 'PropTypes'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
input: 'src/index.js',
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
file: pkg.main,
|
||||||
|
format: 'umd',
|
||||||
|
name: 'ohif-i18n',
|
||||||
|
sourcemap: true,
|
||||||
|
globals
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: pkg.module,
|
||||||
|
format: 'es',
|
||||||
|
sourcemap: true,
|
||||||
|
globals
|
||||||
|
}
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
builtins(),
|
||||||
|
external(),
|
||||||
|
postcss({
|
||||||
|
modules: false
|
||||||
|
}),
|
||||||
|
url(),
|
||||||
|
babel({
|
||||||
|
exclude: 'node_modules/**',
|
||||||
|
externalHelpers: true,
|
||||||
|
runtimeHelpers: true
|
||||||
|
}),
|
||||||
|
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',
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external: Object.keys(pkg.peerDependencies || {}),
|
||||||
|
}
|
||||||
70
extensions/ohif-i18n/src/i18n.js
Executable file
70
extensions/ohif-i18n/src/i18n.js
Executable file
@ -0,0 +1,70 @@
|
|||||||
|
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;
|
||||||
1
extensions/ohif-i18n/src/index.js
Normal file
1
extensions/ohif-i18n/src/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default } from './i18n';
|
||||||
3
extensions/ohif-i18n/src/locales/en-UK/Header.json
Normal file
3
extensions/ohif-i18n/src/locales/en-UK/Header.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"header_test": "Joao Grandao"
|
||||||
|
}
|
||||||
6
extensions/ohif-i18n/src/locales/en-UK/common.json
Executable file
6
extensions/ohif-i18n/src/locales/en-UK/common.json
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"common": {
|
||||||
|
"Welcome to React": "Welcome to React and react-i18next",
|
||||||
|
"welcomeMsg": "welcome"
|
||||||
|
}
|
||||||
|
}
|
||||||
3
extensions/ohif-i18n/src/locales/en-US/Header.json
Normal file
3
extensions/ohif-i18n/src/locales/en-US/Header.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"header_test": "$t(common:test)"
|
||||||
|
}
|
||||||
3
extensions/ohif-i18n/src/locales/en-US/common.json
Executable file
3
extensions/ohif-i18n/src/locales/en-US/common.json
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"tests___": "test common"
|
||||||
|
}
|
||||||
3
extensions/ohif-i18n/src/locales/en/Header.json
Normal file
3
extensions/ohif-i18n/src/locales/en/Header.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"header_test": "$t(common:test)"
|
||||||
|
}
|
||||||
5
extensions/ohif-i18n/src/locales/en/common.json
Executable file
5
extensions/ohif-i18n/src/locales/en/common.json
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Welcome to React": "Welcome to React and react-i18next",
|
||||||
|
"welcomeMsg": "welcome",
|
||||||
|
"test": "Lunch time"
|
||||||
|
}
|
||||||
3929
extensions/ohif-i18n/yarn.lock
Normal file
3929
extensions/ohif-i18n/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@ -94,7 +94,7 @@
|
|||||||
"react-resize-detector": "^3.4.0",
|
"react-resize-detector": "^3.4.0",
|
||||||
"react-router": "^4.3.1",
|
"react-router": "^4.3.1",
|
||||||
"react-router-dom": "^4.3.1",
|
"react-router-dom": "^4.3.1",
|
||||||
"react-viewerbase": "0.4.2",
|
"react-viewerbase": "file:.yalc/react-viewerbase",
|
||||||
"react-vtkjs-viewport": "^0.0.7",
|
"react-vtkjs-viewport": "^0.0.7",
|
||||||
"redux": "^4.0.1",
|
"redux": "^4.0.1",
|
||||||
"redux-oidc": "3.1.x"
|
"redux-oidc": "3.1.x"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"Welcome to React": "Welcome to React and react-i18next",
|
"Welcome to React": "Welcome to React and react-i18next",
|
||||||
"welcomeMsg": "welcome",
|
"welcomeMsg": "welcome",
|
||||||
"test": "Coffee time"
|
"test": "Lunch time"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user