-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
langParser.js: Generate language list dynamically
This adds ``langParser.js`` to generate the available language list automatically from available translation files. This also adds a npm script for generating before webpack bundles. Modifies .gitignore so that generated ``languages.js`` file is ignored. Adds tests. Renames ``nb_NO.json`` to ``nb-NO.json`` to comply with RFC standards. Closes: #125
- Loading branch information
Showing
8 changed files
with
75 additions
and
51 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const fs = require('fs') | ||
const iso639 = require('iso-639-1') | ||
|
||
const availableLanguages = {} | ||
|
||
fs.readdir(`${__dirname}/../static/i18n`, (err, items) => { | ||
items.forEach(function(value) { | ||
const langName = value.substring(0, value.indexOf('.')) | ||
const normalizedName = langName.split('_')[0] | ||
const nativeName = iso639.getNativeName(normalizedName) | ||
availableLanguages[nativeName] = langName | ||
}) | ||
}) | ||
|
||
module.exports = availableLanguages |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{"English":"en","Español":"es","Norsk bokmål":"nb_NO","język polski":"pl"} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
/** | ||
* langParser Library Test | ||
*/ | ||
|
||
const fs = require('fs') | ||
const iso639 = require('iso-639-1') | ||
|
||
const testLangs = ['en', 'es', 'ja_AK', 'fr'] | ||
const expectedLangs = ['English', 'Español', '日本語', 'Français'] | ||
|
||
describe('lib.langParser', () => { | ||
it('should get nativeName for each language', () => { | ||
const resultLangs = [] | ||
testLangs.forEach(function(value) { | ||
const normalizedName = value.split('_')[0] | ||
const nativeName = iso639.getNativeName(normalizedName) | ||
resultLangs.push(nativeName) | ||
}) | ||
|
||
expect(resultLangs).toEqual(expectedLangs) | ||
}) | ||
}) |
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