Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.

Commit 718d69e

Browse files
committed
Include locales in output
1 parent 96536d1 commit 718d69e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ const convertData = (data, locale, options) => {
7474
return Object.keys(data).reduce((res, key) => {
7575
const { includeLocales: il, verbose } = options
7676
const isLcKey = (!il || il.includes(key)) && pluralCategories[key]
77-
if (verbose && isLcKey) console.log(`yaml-to-messageformat: Found locale ${key}`)
77+
if (isLcKey) {
78+
options._lc[key] = true
79+
if (verbose) console.log(`yaml-to-messageformat: Found locale ${key}`)
80+
}
7881
res[key] = convertData(data[key], isLcKey ? key : locale, options)
7982
return res
8083
}, {})
@@ -86,9 +89,14 @@ const convertData = (data, locale, options) => {
8689

8790
const convert = (input, options) => {
8891
options = Object.assign(defaultOptions, options)
92+
options._lc = { [options.defaultLocale]: true }
8993
let data = yaml.safeLoadAll(input, options)
9094
if (data.length === 1) data = data[0]
91-
return convertData(data, options.defaultLocale, options)
95+
const translations = convertData(data, options.defaultLocale, options)
96+
return {
97+
locales: Object.keys(options._lc).filter(lc => lc),
98+
translations
99+
}
92100
}
93101

94102
module.exports = convert

0 commit comments

Comments
 (0)