Commit 9baf4e0c authored by Matija Obreza's avatar Matija Obreza
Browse files

i18n: Moved scan and generate tools from src/

parent ef2b7a0c
{
"action": {
"submit": null
},
"label": {
"loadingData": "Loading data..."
}
......
{
"user": {
"public": {
"form": {
"login": {
"label": {
"password": null,
"username": null
}
}
}
}
}
}
{}
......@@ -4,12 +4,11 @@
"license": "Apache-2.0",
"scripts": {
"precompile": "yarn run i18n:generateI18n",
"i18n:generateI18n": "node src/generateI18n.ts",
"i18n:scanI18nDuplicates": "ts-node src/duplicateDetector.ts",
"i18n:generateI18n": "node tools/generateI18n.ts",
"i18n:scanI18nDuplicates": "ts-node tools/duplicateDetector.ts",
"i18n:i18nscan": "i18next-scanner --config i18next-scanner.config.js '../**/src/**/*.tsx'"
},
"dependencies": {
"@grin-global/ui-core": "file:../ui-core",
"axios": "^0.19.2",
"i18next": "^19.0.3",
"i18next-browser-languagedetector": "^4.0.1",
......@@ -51,7 +50,9 @@
"eslint-plugin-react": "^7.18.0",
"file-system": "^2.2.2",
"i18next-scanner": "^2.10.3",
"js-md5": "^0.7.3",
"lerna": "^3.20.2",
"readline-sync": "^1.4.10",
"rimraf": "^3.0.1",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
......
import languages from '@grin-global/i18n/data/Languages';
import languages from '@gringlobal/i18n/data/Languages';
export default function detectLocaleFromPath(virtualPath: string, path: string, index: number) {
if (virtualPath && path.startsWith(virtualPath)) {
......
......@@ -2,9 +2,9 @@
import i18n from 'i18next';
import axios from 'axios';
// eslint-disable-next-line no-restricted-imports
import optionsBase from '@grin-global/i18n/options-base';
import optionsBase from '@gringlobal/i18n/options-base';
// eslint-disable-next-line no-restricted-imports
import langDetector from '@grin-global/i18n/langDetector';
import langDetector from '@gringlobal/i18n/langDetector';
import XHR from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
......
// @ts-ignore
import i18n from 'i18next';
import * as path from 'path';
import optionsBase from '@grin-global/i18n/options-base';
import optionsBase from '@gringlobal/i18n/options-base';
import Backend from 'i18next-sync-fs-backend';
import { initReactI18next } from 'react-i18next';
......
import detectLocaleFromPath from '@grin-global/i18n/detectLocaleFromPath';
import detectLocaleFromPath from '@gringlobal/i18n/detectLocaleFromPath';
export default {
name: 'catalogLangDetector',
name: 'pathStartLangDetector',
lookup: function lookup(options) {
let found;
......
......@@ -5,9 +5,17 @@ const md5 = require('js-md5');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');
const getPrefix = (path) => path.substring(path.indexOf('./src/') + './src/'.length, path.indexOf('/translations.json'));
const getPrefix = (path) => {
console.log(`Converting ${path}`);
return path.substring(path.indexOf('./src/') + './src/'.length, path.indexOf('/translations.json'));
};
// TODO fix generated paths
fg(['../../**/src/**/translations.json', '../../**/src/translations.json'])
.then((entries) => {
console.log(`Inspecting ${entries}`);
return entries.filter((e) => ! /\/node_modules\//.test(e));
})
.then((entries) => entries.sort((a, b) => getPrefix(a).localeCompare(getPrefix(b))))
.then((entries) => {
let result = {};
......@@ -38,11 +46,11 @@ const generateHashedLocales = () => {
const newFilePath = path.replace('locales', 'generated/locales').replace('.json', `-${ contentHash }.json`); // adding hash before .json
const generatedLocaleDirPath = newFilePath.substring(0, newFilePath.lastIndexOf('/')); // getting all but the filename as folder of locale lang
mkdirp.sync(generatedLocaleDirPath); // create dir if no exist
fs.writeFileSync(newFilePath, fileContent, {flag: 'wx'});
fs.writeFileSync(newFilePath, fileContent, { flag: 'wx' });
localeHashMapping[path.substring(1)] = newFilePath.replace('./generated', ''); // deleting '/generated' from new path for further loading
// console.log(`Generated ${ newFilePath } for ${ path }`);
});
fs.writeFileSync('./generated/locales/localesMapping.json', JSON.stringify(localeHashMapping), {encoding: 'utf8'}); // after all locales moved creating file with mappings
fs.writeFileSync('./generated/locales/localesMapping.json', JSON.stringify(localeHashMapping), { encoding: 'utf8' }); // after all locales moved creating file with mappings
});
});
});
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment