forked from LemmyNet/lemmy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate typescript during compilation
- Loading branch information
Showing
20 changed files
with
74 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ docker/lemmy_mine.hjson | |
docker/dev/env_deploy.sh | ||
build/ | ||
.idea/ | ||
ui/src/translations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
import i18next from 'i18next'; | ||
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 { | ||
return format === 'uppercase' ? value.toUpperCase() : value; | ||
} | ||
|
||
i18next | ||
.use(XHR) | ||
.init({ | ||
debug: true, | ||
//load: 'languageOnly', | ||
i18next.init({ | ||
debug: false, | ||
// load: 'languageOnly', | ||
|
||
// initImmediate: false, | ||
lng: getLanguage(), | ||
fallbackLng: 'en', | ||
interpolation: { format }, | ||
backend: { | ||
loadPath: '/static/assets/translations/{{lng}}.json', | ||
} | ||
// initImmediate: false, | ||
lng: getLanguage(), | ||
fallbackLng: 'en', | ||
resources, | ||
interpolation: { format }, | ||
}); | ||
|
||
export { i18next as i18n, resources }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters