Convert *.po GNU Gettext files to Vue i18n compatible JSON files
Usage no npm install needed!
<script type="module">
import poToVueI18n from 'https://cdn.skypack.dev/po-to-vue-i18n';
</script>
README
po-to-vue-i18n-json
Convert PO GNU Gettext files to Vue i18n compatible JSON files. It has support for plurals and can be imported as a Node module or be executed directly on the command line.
Usage as a Node module
import { po2Vuei18nJSON, po2Vuei18nJSONFromUri } from 'po-to-vue-i18n-json';
// Get JSON from PO string
const json = po2Vuei18nJSON('\
msgctxt "context"\n\
msgid "test"\n\
msgstr "prueba"\n\
');
// Get JSON from Uri
const json = po2Vuei18nJSONFromUri('https://example.com/my-po-file.po');
Executing from the command line
NOTE: when executing on the command line, only URI paramaters are supported.
When providing plural translations on the original PO file by specifying the fields "msgid_plural" and "msgstr[n]", the results will have the following structure:
The plural forms are obtained from msgstr array specified by the PO content. If the array is incomplete on the PO file (ex: msgstr[0] and msgstr[2] are defined, but msgstr[1] is not), "msgid_plural" will be used as fallback value.