Skip to content

Commit

Permalink
Re-generated locale data files
Browse files Browse the repository at this point in the history
  • Loading branch information
purecatamphetamine committed Oct 9, 2020
1 parent 21ac42d commit 58a879d
Show file tree
Hide file tree
Showing 483 changed files with 53,009 additions and 1,509 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
TO DO: Add the ability to use the native `Intl.RelativeTimeFormat` and `Intl.PluralRules` and not import any locale data (except for maybe doing `TimeAgo.addLabels('en', 'now', require('javascript-time-ago/locale/en/now.json')`).
https://github.com/catamphetamine/javascript-time-ago/issues/21
TO DO: Change the export of the bundle: current — `new window['javascript-time-ago'].default()`, a more appropriate one — `new TimeAgo()`. Actually, would it even work in a browser? And will also including `relative-time-format` be required. Maybe add a "CDN" secition in the README (and a note in the "Install" section).
TO DO: Maybe create a "dummy" `time-ago-js` package that would simply re-export `javascript-time-ago`.
TO DO: Added the ability to use native `Intl.RelativeTimeFormat` instead of the polyfill.
Expand Down Expand Up @@ -40,6 +42,10 @@ TO DO: if `style` is passed as an object then maybe it should be passed as part

* Updated `relative-time-format` to the latest version: `0.1.x` -> `1.0.0`.

* Locale files are now `*.json` files. There's no `quantify` function there now: now it's just labels. `{locale}/index.js` files are still there just for legacy compatibility.

* The bundle is now generated by Rollup rather than Webpack.

2.1.5 / 07.10.2020
==================

Expand Down
62 changes: 31 additions & 31 deletions bin/generate-locale-messages.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path from 'path'
import fs from 'fs-extra'

for (const locale of listAllRelativeTimeFormatLocales())
{
const localeData = require('relative-time-format/locale/' + locale)
const localesDirectory = path.join(__dirname, '../locale')

const localeDirectory = path.join(__dirname, '../locale', locale)
for (const locale of listAllRelativeTimeFormatLocales()) {
const localeData = require('relative-time-format/locale/' + locale)

// Extra flavors.
const EXTRA_STYLES = [
Expand All @@ -18,7 +17,7 @@ for (const locale of listAllRelativeTimeFormatLocales())
const extraStyleDirectories = {}

for (const style of EXTRA_STYLES) {
const directory = findFlavorDirectory(locale, style)
const directory = findLabelsStyleDirectory(locale, style)
if (directory) {
extraStyleDirectories[style] = directory
if (style === 'mini-time') {
Expand All @@ -28,51 +27,52 @@ for (const locale of listAllRelativeTimeFormatLocales())
}
}

// Create `index.js` file in the locale directory.
const extendedLocaleData = {
...localeData,
locale
}

for (const style of Object.keys(extraStyleDirectories)) {
extendedLocaleData[style] = require(extraStyleDirectories[style] + '/' + (style === 'tiny' ? 'mini-time' : style) + '.json')
}

// Create the locale *.json file.
fs.outputFileSync(
path.join(localeDirectory, 'index.js'),
`
var locale = require('relative-time-format/locale/${locale}')
path.join(localesDirectory, `${locale}.json`),
JSON.stringify(extendedLocaleData, null, '\t')
)

module.exports = {
${[
'locale: locale.locale',
'// Standard styles.',
'long: locale.long',
'short: locale.short',
'narrow: locale.narrow',
Object.keys(extraStyleDirectories).length > 0 && '// Additional styles.',
extraStyleDirectories.tiny && '// "tiny" is a legacy name of "mini".',
...Object.keys(extraStyleDirectories).map(style => "'" + style + "': require('" + extraStyleDirectories[style] + "/" + (style === 'tiny' ? 'mini-time' : style) + ".json')")
]
.filter(_ => _)
.join(',\n\t')
.replace(/\.,\n/g, '.\n')}
}
`.trim()
// Create the legacy-compatibility `index.js` file.
const localeDirectory = path.join(localesDirectory, locale)
fs.outputFileSync(
path.join(localeDirectory, 'index.js'),
`module.exports = require('../${locale}.json')`
)
}


/**
* Returns a list of all locales supported by `relative-time-format`.
* @return {string[]}
*/
export function listAllRelativeTimeFormatLocales() {
const LOCALE_FILE_NAME_REG_EXP = /([^\/]+)\.json$/
return fs.readdirSync(path.join(__dirname, '../node_modules/relative-time-format/locale/'))
.filter(_ => fs.statSync(path.join(__dirname, '../node_modules/relative-time-format/locale', _)).isDirectory())
.filter(_ => fs.statSync(path.join(__dirname, '../node_modules/relative-time-format/locale', _)).isFile() && LOCALE_FILE_NAME_REG_EXP.test(_))
.map(_ => _.match(LOCALE_FILE_NAME_REG_EXP)[1])
}

/**
* Returns the relative path to a directory where
* a given "flavor" (short, long, narrow) labels file
* a given labels "style" (short, long, narrow) labels file
* resides for a given locale.
* @param {string} locale
* @param {string} flavor
* @param {string} labelsStyle
* @return {string} [directory]
*/
function findFlavorDirectory(locale, flavor) {
if (fs.existsSync(path.join(__dirname, '../locale-more-styles', locale, `${flavor}.json`))) {
return `../../locale-more-styles/${locale}`
function findLabelsStyleDirectory(locale, labelsStyle) {
if (fs.existsSync(path.join(__dirname, '../locale-more-styles', locale, `${labelsStyle}.json`))) {
return `../locale-more-styles/${locale}`
}
}

Expand Down
106 changes: 106 additions & 0 deletions load-all-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,101 @@ TimeAgo.addLocale(require("javascript-time-ago/locale/dz"))
TimeAgo.addLocale(require("javascript-time-ago/locale/ee"))
TimeAgo.addLocale(require("javascript-time-ago/locale/el"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-001"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-150"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-AG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-AI"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-AT"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-AU"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BB"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BS"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-BZ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CA"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CC"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CH"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CX"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-CY"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-DE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-DG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-DK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-DM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-ER"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-FI"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-FJ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-FK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-FM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GB"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GD"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GH"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GI"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-GY"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-HK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-IE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-IL"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-IM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-IN"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-IO"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-JE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-JM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-KE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-KI"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-KN"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-KY"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-LC"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-LR"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-LS"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MO"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MS"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MT"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MU"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-MY"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NA"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NF"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NL"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NR"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NU"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-NZ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-PG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-PH"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-PK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-PN"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-PW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-RW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SB"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SC"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SD"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SE"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SH"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SI"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SL"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SS"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SX"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-SZ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TC"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TK"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TO"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TT"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TV"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-TZ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-UG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-VC"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-VG"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-VU"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-WS"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-ZA"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-ZM"))
TimeAgo.addLocale(require("javascript-time-ago/locale/en-ZW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/es"))
TimeAgo.addLocale(require("javascript-time-ago/locale/es-AR"))
TimeAgo.addLocale(require("javascript-time-ago/locale/es-MX"))
Expand Down Expand Up @@ -91,6 +186,17 @@ TimeAgo.addLocale(require("javascript-time-ago/locale/pa"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pl"))
TimeAgo.addLocale(require("javascript-time-ago/locale/ps"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-AO"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-CH"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-CV"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-GQ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-GW"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-LU"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-MO"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-MZ"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-PT"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-ST"))
TimeAgo.addLocale(require("javascript-time-ago/locale/pt-TL"))
TimeAgo.addLocale(require("javascript-time-ago/locale/qu"))
TimeAgo.addLocale(require("javascript-time-ago/locale/ro"))
TimeAgo.addLocale(require("javascript-time-ago/locale/ru"))
Expand Down
Loading

0 comments on commit 58a879d

Please sign in to comment.