Split packages into platform and extensions

This commit is contained in:
dannyrb committed 2019-07-08 00:41:25 -04:00
1 parent f175d4b96b
commit e8969fba11
992 files changed
+2 -1

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
# 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
# Note: DO NOT include this file because it includes our API key
.locize
+21
View 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.
+4
View File
@@ -0,0 +1,4 @@
# @ohif/i18n
More information available at
[OHIF Docs](https://docs.ohif.org/essentials/translating.html).
+67
View File
@@ -0,0 +1,67 @@
const path = require('path');
const webpack = require('webpack');
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
const SRC_DIR = path.join(__dirname, '../src');
const DIST_DIR = path.join(__dirname, '../dist');
module.exports = (env, argv) => {
return {
entry: {
app: `${SRC_DIR}/index.js`,
},
context: SRC_DIR,
resolve: {
extensions: ['.js', '.jsx', '.json', '*'],
symlinks: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: [/node_modules/],
loader: 'babel-loader',
options: {
// Find babel.config.js in monorepo root
// https://babeljs.io/docs/en/options#rootmode
rootMode: 'upward',
presets: [
[
'@babel/preset-env',
{
// Do not transform ES6 modules to another format.
// Webpack will take care of that.
modules: false,
},
],
],
},
},
{
test: /\.css$/,
use: [
'style-loader',
ExtractCssChunks.loader,
{ loader: 'css-loader', options: { importLoaders: 1 } },
{
loader: 'postcss-loader',
options: {
config: {
path: './postcss.config.js',
},
},
},
],
},
],
},
plugins: [
new webpack.EnvironmentPlugin(['NODE_ENV']),
new ExtractCssChunks({
filename: '[name].css',
chunkFilename: '[id].css',
// hot: true /* only necessary if hot reloading not function*/
}),
],
};
};
+64
View File
@@ -0,0 +1,64 @@
const merge = require('webpack-merge');
const path = require('path');
const common = require('./webpack.common');
const pkg = require('./../package.json');
const ROOT_DIR = path.join(__dirname, './..');
const SRC_DIR = path.join(__dirname, '../src');
const DIST_DIR = path.join(__dirname, '../dist');
module.exports = (env, argv) => {
const commonConfig = common(env, argv);
return merge(commonConfig, {
mode: 'production',
stats: {
colors: false,
hash: true,
timings: true,
assets: true,
chunks: true,
chunkModules: true,
modules: true,
children: true,
warnings: true,
},
optimization: {
minimize: true,
sideEffects: true,
},
output: {
path: ROOT_DIR,
library: 'ohifCornerstoneExtension',
libraryTarget: 'umd',
filename: pkg.main,
auxiliaryComment: 'Test Comment',
},
module: {
rules: [
{
test: /\.(gif|jpe?g|png|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
{
test: /\.(ttf|eot|woff|woff2)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 50000,
},
},
],
},
],
},
});
};
+48
View File
@@ -0,0 +1,48 @@
{
"name": "@ohif/i18n",
"version": "0.2.2",
"description": "OHIF extension for 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",
"lerna:build": "webpack --config config/webpack.prod.js -w -d",
"prepublishOnly": "npm run build",
"pullTranslations": "./pullTranslations.sh"
},
"peerDependencies": {
"i18next": "^17.0.3",
"i18next-browser-languagedetector": "^3.0.1",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-i18next": "^10.11.0"
},
"devDependencies": {
"i18next": "^15.1.3",
"i18next-browser-languagedetector": "^3.0.1",
"locize-cli": "^4.8.0",
"react-i18next": "^10.11.0"
},
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"dependencies": {
"@babel/runtime": "^7.2.0",
"classnames": "^2.2.6",
"i18next-locize-backend": "^2.0.0",
"locize-editor": "^2.0.0",
"locize-lastused": "^1.1.0",
"rollup-plugin-json": "^4.0.0"
}
}
+4
View File
@@ -0,0 +1,4 @@
rm -rf src/locales/
cd src/locales/
npx locize --config-path ../../.locize download --ver latest
node ./writeLocaleIndexFiles.js
+67
View File
@@ -0,0 +1,67 @@
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';
import json from 'rollup-plugin-json';
const globals = {
react: 'React',
'react-dom': 'ReactDOM',
'react-redux': 'ReactRedux',
'react-resize-detector': 'ReactResizeDetector',
'prop-types': 'PropTypes',
i18next: 'i18next',
'react-i18next': 'react-i18next',
'i18next-browser-languagedetector': 'LngDetector',
};
export default {
input: 'src/index.js',
output: [
{
file: pkg.main,
format: 'umd',
name: 'ohif-i18n',
sourcemap: true,
globals,
exports: 'named',
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
globals,
exports: 'named',
},
],
plugins: [
builtins(),
external(),
postcss({
modules: false,
}),
json({
// ignores indent and generates the smallest code
compact: true, // Default: false
// generate a named export for every property of the JSON object
namedExports: true, // Default: true
}),
url(),
babel({
exclude: 'node_modules/**',
externalHelpers: true,
runtimeHelpers: true,
}),
resolve(),
commonjs({
include: ['node_modules/**', '.yalc/**'],
}),
],
external: Object.keys(pkg.peerDependencies || {}),
};
+24
View File
@@ -0,0 +1,24 @@
const debugMode = !!(
process.env.NODE_ENV !== 'production' && process.env.REACT_APP_I18N_DEBUG
);
const detectionOptions = {
// order and from where user language should be detected
order: ['querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
// keys or params to lookup language from
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
lookupFromPathIndex: 0,
lookupFromSubdomainIndex: 0,
// cache user language on
caches: ['localStorage', 'cookie'],
excludeCacheFor: ['cimode'], // languages to not persist (cookie, localStorage)
// optional htmlTag with lang attribute, the default is:
htmlTag: document.documentElement
};
export { debugMode, detectionOptions };
+8
View File
@@ -0,0 +1,8 @@
import { debugMode } from './config';
export default (message, level = 'log') => {
if (debugMode) {
// eslint-disable-next-line
console[level]('@ohif/i18n: ', message);
}
};
+140
View File
@@ -0,0 +1,140 @@
import i18n from 'i18next';
import Backend from 'i18next-locize-backend';
import LastUsed from 'locize-lastused';
import Editor from 'locize-editor';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import customDebug from './debugger';
import pkg from '../package.json';
import { debugMode, detectionOptions } from './config';
// Note: The index.js files inside src/locales are dynamically generated
// by the pullTranslations.sh script
import locales from './locales';
function addLocales(newLocales) {
customDebug(`Adding locales ${newLocales}`, 'info');
let resourceBundle = [];
Object.keys(newLocales).map(key => {
Object.keys(newLocales[key]).map(namespace => {
const locale = newLocales[key][namespace];
resourceBundle.push({ key, namespace, locale });
i18n.addResourceBundle(key, namespace, locale, true, true);
});
});
customDebug(`Locales added successfully`, 'info');
customDebug(resourceBundle, 'info');
}
// Note: Developers can add the API key to use the in-context editor.
// DO NOT commit the API key
const config = (window.config && window.config.i18n) || {};
const locizeOptions = {
projectId: config.LOCIZE_PROJECTID,
apiKey: config.LOCIZE_API_KEY,
referenceLng: 'en-US',
fallbacklng: 'en-US',
};
const envUseLocize = !!config.USE_LOCIZE;
const envApiKeyAvailable = !!config.LOCIZE_API_KEY;
function initI18n(
detection = detectionOptions,
useLocize = envUseLocize,
apiKeyAvailable = envApiKeyAvailable
) {
let initialized;
if (useLocize) {
customDebug(`Using Locize for translation files`, 'info');
initialized = i18n
// i18next-locize-backend
// loads translations from your project, saves new keys to it (saveMissing: true)
// https://github.com/locize/i18next-locize-backend
.use(Backend)
// locize-lastused
// sets a timestamp of last access on every translation segment on locize
// -> safely remove the ones not being touched for weeks/months
// https://github.com/locize/locize-lastused
.use(LastUsed)
// locize-editor
// InContext Editor of locize ?locize=true to show it
// https://github.com/locize/locize-editor
.use(Editor)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: 'en-US',
saveMissing: apiKeyAvailable,
debug: debugMode,
keySeparator: false,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
detection,
backend: locizeOptions,
locizeLastUsed: locizeOptions,
editor: {
...locizeOptions,
onEditorSaved: async (lng, ns) => {
// reload that namespace in given language
await i18n.reloadResources(lng, ns);
// trigger an event on i18n which triggers a rerender
// based on bindI18n below in react options
i18n.emit('editorSaved');
},
},
react: {
useSuspense: false, // TODO: Was seeing weird errors without this
wait: true,
bindI18n: 'languageChanged editorSaved',
},
});
} else {
customDebug(`Using local translation files`, 'info');
initialized = i18n
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: 'en-US',
resources: locales,
debug: debugMode,
keySeparator: false,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
detection,
react: {
wait: true,
},
});
}
return initialized.then(function(t) {
i18n.T = t;
customDebug(`T function available.`, 'info');
});
}
customDebug(`version ${pkg.version} loaded.`, 'info');
i18n.initializing = initI18n();
i18n.initI18n = initI18n;
i18n.addLocales = addLocales;
export default i18n;
@@ -0,0 +1,42 @@
{
"Acquired": "Acquired",
"Angle": "Angle",
"Axial": "Axial",
"Bidirectional": "Bidirectional",
"Brush": "Brush",
"CINE": "CINE",
"Cancel": "Cancel",
"Circle": "Circle",
"Clear": "Clear",
"Coronal": "Coronal",
"Crosshairs": "Crosshairs",
"Ellipse": "Ellipse",
"Elliptical": "Elliptical",
"Flip H": "Flip H",
"Flip V": "Flip V",
"Freehand": "Freehand",
"Invert": "Invert",
"Layout": "$t(Common:Layout)",
"Length": "Length",
"Levels": "Levels",
"Magnify": "Magnify",
"Manual": "Manual",
"Measurements": "Measurements",
"More": "$t(Common:More)",
"Next": "$t(Common:Next)",
"Pan": "Pan",
"Play": "$t(Common:Play)",
"Previous": "$t(Common:Previous)",
"Probe": "Probe",
"ROI Window": "ROI Window",
"Rectangle": "Rectangle",
"Reset": "$t(Common:Reset)",
"Reset to Defaults": "$t(Common:Reset) to Defaults",
"Rotate Right": "Rotate Right",
"Sagittal": "Sagittal",
"Save": "Save",
"Stack Scroll": "Stack Scroll",
"Stop": "$t(Common:Stop)",
"Themes": "Themes",
"Zoom": "Zoom"
}
@@ -0,0 +1,8 @@
{
"Next image": "$t(Common:Play) $t(Common:Image)",
"Play / Stop": "$t(Common:Play) / $t(Common:Stop)",
"Previous image": "$t(Common:Previous) $t(Common:Image)",
"Skip to first image": "Skip to first $t(Common:Image)",
"Skip to last image": "Skip, to last $t(Common:Image)",
"fps": "fps"
}
@@ -0,0 +1,10 @@
{
"Image": "Image",
"Layout": "Layout",
"More": "More",
"Next": "Next",
"Play": "Play",
"Previous": "Previous",
"Reset": "Reset",
"Stop": "Stop"
}
@@ -0,0 +1,8 @@
{
"About": "About",
"Back to Viewer": "Back to Viewer",
"INVESTIGATIONAL USE ONLY": "INVESTIGATIONAL USE ONLY",
"Options": "Options",
"Preferences": "Preferences",
"Study list": "Study list"
}
@@ -0,0 +1,9 @@
{
"Criteria nonconformities": "Criteria nonconformities",
"Delete": "Delete",
"Description": "Description",
"MAX": "MAX",
"NonTargets": "NonTargets",
"Relabel": "Relabel",
"Targets": "Targets"
}
@@ -0,0 +1,6 @@
{
"Cancel": "$t(Buttons:Cancel)",
"Reset to Defaults": "$t(Buttons:Reset to Defaults)",
"Save": "$t(Buttons:Save)",
"User Preferences": "User Preferences"
}
+17
View File
@@ -0,0 +1,17 @@
import Buttons from './Buttons.json';
import CineDialog from './CineDialog.json';
import Common from './Common.json';
import Header from './Header.json';
import MeasurementTable from './MeasurementTable.json';
import UserPreferencesModal from './UserPreferencesModal.json';
export default {
'en-US': {
Buttons,
CineDialog,
Common,
Header,
MeasurementTable,
UserPreferencesModal,
},
};
+42
View File
@@ -0,0 +1,42 @@
{
"Acquired": "Acquired",
"Angle": "Ángulo",
"Axial": "Axial",
"Bidirectional": "Bidirectional",
"Brush": "Escoba",
"CINE": "CINE",
"Cancel": "Cancelar",
"Circle": "Circle",
"Clear": "Limpiar",
"Coronal": "Coronal",
"Crosshairs": "Cruces",
"Ellipse": "Elipse",
"Elliptical": "Elliptical",
"Flip H": "Espejo Hor.",
"Flip V": "Espejo Ver.",
"Freehand": "Freehand",
"Invert": "Invertido",
"Layout": "$t(Common:Layout)",
"Length": "Medición",
"Levels": "Niveles",
"Magnify": "Lupa",
"Manual": "Manual",
"Measurements": "Medidas",
"More": "$t(Common:More)",
"Next": "$t(Common:Next)",
"Pan": "Mover",
"Play": "$t(Common:Play)",
"Previous": "$t(Common:Previous)",
"Probe": "Probar",
"ROI Window": "Ventana ROI",
"Rectangle": "Rectángulo",
"Reset": "$t(Common:Reset)",
"Reset to Defaults": "$t(Common:reset) por defectos",
"Rotate Right": "Rotar ->",
"Sagittal": "Sagittal",
"Save": "Guardar",
"Stack Scroll": "Avance X slice",
"Stop": "$t(Common:Stop)",
"Themes": "Temas",
"Zoom": "Zoom"
}
@@ -0,0 +1,8 @@
{
"Next image": "$t(Common:Play) $t(Common:Image)",
"Play / Stop": "$t(Common:Play) / $t(Common:Stop)",
"Previous image": "$t(Common:Previous) $t(Common:Image)",
"Skip to first image": "Avanza para la primera $t(Common:Image)",
"Skip to last image": "Pular para la ultima $t(Common:Image)",
"fps": "fps"
}
+10
View File
@@ -0,0 +1,10 @@
{
"Image": "Imagen",
"Layout": "Esquema",
"More": "Más",
"Next": "Próximo",
"Play": "Play",
"Previous": "Anterior",
"Reset": "Reiniciar",
"Stop": "Stop"
}
+8
View File
@@ -0,0 +1,8 @@
{
"About": "Sobre",
"Back to Viewer": "Back to Viewer",
"INVESTIGATIONAL USE ONLY": "SOLO USO DE INVESTIGACIÓN",
"Options": "Opciones",
"Preferences": "Preferencias",
"Study list": "Lista de estudio"
}
@@ -0,0 +1,9 @@
{
"Criteria nonconformities": "Criterios de no conformidades",
"Delete": "Borrar",
"Description": "Descripción",
"MAX": "máximo",
"NonTargets": "NonObjetivos",
"Relabel": "Reetiquetar",
"Targets": "Objetivos"
}
@@ -0,0 +1,6 @@
{
"Cancel": "$t(Buttons:Cancel)",
"Reset to Defaults": "$t(Buttons:Reset to Defaults)",
"Save": "$t(Buttons:Save)",
"User Preferences": "Preferencias de usuario"
}
+17
View File
@@ -0,0 +1,17 @@
import Buttons from './Buttons.json';
import CineDialog from './CineDialog.json';
import Common from './Common.json';
import Header from './Header.json';
import MeasurementTable from './MeasurementTable.json';
import UserPreferencesModal from './UserPreferencesModal.json';
export default {
es: {
Buttons,
CineDialog,
Common,
Header,
MeasurementTable,
UserPreferencesModal,
},
};
+9
View File
@@ -0,0 +1,9 @@
import en_US from './en-US/';
import es from './es/';
import nl from './nl/';
export default {
...en_US,
...es,
...nl,
};
@@ -0,0 +1,6 @@
{
"Circle": "Cirkel",
"More": "Meer",
"Pan": "Pan",
"Zoom": "Inzoomen"
}
+3
View File
@@ -0,0 +1,3 @@
{
"More": "Meer"
}
+7
View File
@@ -0,0 +1,7 @@
{
"About": "Over",
"INVESTIGATIONAL USE ONLY": "ALLEEN VOOR ONDERZOEK",
"Options": "Opties",
"Preferences": "Voorkeuren",
"Study list": "Studie Overzicht"
}
+11
View File
@@ -0,0 +1,11 @@
import Buttons from './Buttons.json';
import Common from './Common.json';
import Header from './Header.json';
export default {
nl: {
Buttons,
Common,
Header,
},
};
+92
View File
@@ -0,0 +1,92 @@
const path = require('path');
const fs = require('fs');
const directoryPath = path.join(__dirname, 'src', 'locales');
const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
const isDirectory = source => lstatSync(source).isDirectory();
const getDirectories = source =>
readdirSync(source)
.map(name => join(source, name))
.filter(isDirectory);
const getJSONFiles = source =>
readdirSync(source)
.filter(name => name.includes('.json'))
.map(name => join(source, name))
.filter(a => !isDirectory(a));
const directories = getDirectories(directoryPath);
function writeFile(filepath, name, content) {
fs.writeFile(path.join(filepath, name), content, err => {
if (err) throw err;
});
}
// For each language directory
const languages = [];
directories.forEach(directory => {
const language = path.basename(directory);
languages.push(language);
const name = 'index.js';
// Create one file (index.js) inside the language folder
// For each namespace
let content = '';
const files = getJSONFiles(directory);
const namespaces = files.map(file => path.basename(file, '.json'));
files.forEach(file => {
const filename = path.basename(file);
const namespace = path.basename(file, '.json');
content += `import ${namespace} from "./${filename}";\n`;
});
content += '\n';
let exportLines = `export default { \n '${language}': {\n`;
namespaces.forEach(namespace => {
exportLines += ` ${namespace},\n`;
});
exportLines += ' }\n};';
content += exportLines;
// If the file {namespace}.json is present,
// create a file to import the namespace and
// export all of the namespaces for the language
// e.g.
// import namespace from './{namespace}.json';
// export { namespace1, namespace2, ... }
writeFile(directory, name, content);
});
let fileContent = '';
const languageVariables = languages.map(language => {
const languageVariable = language.replace('-', '_');
fileContent += `import ${languageVariable} from './${language}/';\n`;
return languageVariable;
});
fileContent += '\n';
fileContent += 'export default {\n';
languageVariables.forEach(language => {
fileContent += ` ...${language},\n`;
});
fileContent += '};';
// Create one file (index.js) inside the locales folder
// which exports each of the languages
// e.g.
// import language1 from './{language1}/'
// import language2 from './{language2}/'
//
// export { language1, language2 }
writeFile(directoryPath, 'index.js', fileContent);