forked from coala/gci-leaders
-
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.
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. Closes: coala#125
- Loading branch information
Showing
6 changed files
with
47 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ out | |
yarn.lock | ||
.DS_Store | ||
**.orig | ||
src/js/languages.js |
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,20 @@ | ||
const fs = require('fs') | ||
const iso639 = require('iso-639-1') | ||
|
||
fs.readdir(`${__dirname}/../static/i18n`, function(err, items) { | ||
var avaliableLanguages = { | ||
Languages: {}, | ||
} | ||
for (var i = 0; i < items.length; i++) { | ||
var langName = items[i].substring(0, items[i].indexOf('.')) | ||
var normalizedName = langName.split('-')[0] | ||
var nativeName = iso639.getNativeName(normalizedName) | ||
avaliableLanguages['Languages'][nativeName] = langName | ||
} | ||
fs.writeFileSync( | ||
`${__dirname}/../src/js/languages.js`, | ||
'export default ' + | ||
JSON.stringify(avaliableLanguages) + | ||
' // eslint-disable-line' | ||
) | ||
}) |
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
File renamed without changes.