mirror of https://github.com/LemmyNet/lemmy
generate typescript during compilation
parent
51653015a0
commit
d7f49cea9a
@ -0,0 +1,25 @@
|
|||||||
|
fs = require('fs');
|
||||||
|
|
||||||
|
fs.mkdirSync('src/translations/', { recursive: true });
|
||||||
|
fs.readdir('translations', (err, files) => {
|
||||||
|
files.forEach(filename => {
|
||||||
|
const lang = filename.split('.')[0];
|
||||||
|
try {
|
||||||
|
const json = JSON.parse(
|
||||||
|
fs.readFileSync('translations/' + filename, 'utf8')
|
||||||
|
);
|
||||||
|
var data = `export const ${lang} = {\n translation: {`;
|
||||||
|
for (var key in json) {
|
||||||
|
if (key in json) {
|
||||||
|
const value = json[key].replace(/"/g, '\\"');
|
||||||
|
data = `${data}\n ${key}: "${value}",`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data += '\n },\n};';
|
||||||
|
const target = 'src/translations/' + lang + '.ts';
|
||||||
|
fs.writeFileSync(target, data);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
@ -1,24 +1,51 @@
|
|||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import { getLanguage } from './utils';
|
import { getLanguage } from './utils';
|
||||||
import XHR from 'i18next-xhr-backend';
|
import { en } from './translations/en';
|
||||||
|
import { eo } from './translations/eo';
|
||||||
|
import { es } from './translations/es';
|
||||||
|
import { de } from './translations/de';
|
||||||
|
import { fr } from './translations/fr';
|
||||||
|
import { sv } from './translations/sv';
|
||||||
|
import { ru } from './translations/ru';
|
||||||
|
import { zh } from './translations/zh';
|
||||||
|
import { nl } from './translations/nl';
|
||||||
|
import { it } from './translations/it';
|
||||||
|
import { fi } from './translations/fi';
|
||||||
|
import { ca } from './translations/ca';
|
||||||
|
import { fa } from './translations/fa';
|
||||||
|
import { pt_br } from './translations/pt_br';
|
||||||
|
|
||||||
|
// https://github.com/nimbusec-oss/inferno-i18next/blob/master/tests/T.test.js#L66
|
||||||
|
const resources = {
|
||||||
|
en,
|
||||||
|
eo,
|
||||||
|
es,
|
||||||
|
de,
|
||||||
|
zh,
|
||||||
|
fr,
|
||||||
|
sv,
|
||||||
|
ru,
|
||||||
|
nl,
|
||||||
|
it,
|
||||||
|
fi,
|
||||||
|
ca,
|
||||||
|
fa,
|
||||||
|
pt_br,
|
||||||
|
};
|
||||||
|
|
||||||
function format(value: any, format: any, lng: any): any {
|
function format(value: any, format: any, lng: any): any {
|
||||||
return format === 'uppercase' ? value.toUpperCase() : value;
|
return format === 'uppercase' ? value.toUpperCase() : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
i18next
|
i18next.init({
|
||||||
.use(XHR)
|
debug: false,
|
||||||
.init({
|
// load: 'languageOnly',
|
||||||
debug: true,
|
|
||||||
//load: 'languageOnly',
|
|
||||||
|
|
||||||
// initImmediate: false,
|
// initImmediate: false,
|
||||||
lng: getLanguage(),
|
lng: getLanguage(),
|
||||||
fallbackLng: 'en',
|
fallbackLng: 'en',
|
||||||
interpolation: { format },
|
resources,
|
||||||
backend: {
|
interpolation: { format },
|
||||||
loadPath: '/static/assets/translations/{{lng}}.json',
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export { i18next as i18n, resources };
|
export { i18next as i18n, resources };
|
||||||
|
Loading…
Reference in New Issue