Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

[WIP] Nodejs i18n module #133

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
*.tgz
temp
.idea
index.json
TiagoDanin marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions lib/locales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const fs = require('fs')
const path = require('path')
const contentDir = path.join(__dirname, '../content')

const {
getLanguageName,
getLanguageNativeName,
getCountryCode,
getCountryName
} = require('locale-code')

module.exports = fs.readdirSync(contentDir)
.filter(file => fs.statSync(path.join(contentDir, file)).isDirectory())
.map(version => {
const locales = fs.readdirSync(path.join(contentDir, version))
.filter(file => fs.statSync(path.join(contentDir, version, file)).isDirectory())
.map(locale => {
let result = {
locale,
languageName: getLanguageName(locale),
languageNativeName: getLanguageNativeName(locale),
countryCode: getCountryCode(locale),
countryName: getCountryName(locale)
}

// Override some `locale-code` names
if (locale === 'zh-TW') result.languageName = 'Chinese Traditional'
if (locale === 'zh-CN') result.languageName = 'Chinese Simplified'
if (locale === 'en-CA') result.languageName = 'English (Canada)'

return result
}).reduce((acc, locale) => {
acc[locale.locale] = locale
return acc
}, {})

let result = {
version,
locales
}

return result
})
Loading