ilib-loctool-javascript-resource
v1.3.0
Published
A loctool plugin that knows how to process JS resource files
Downloads
64
Maintainers
Readme
ilib-loctool-javascript-resource
ilib-loctool-javascript-resource is a plugin for the loctool that
writes localized strings to JavaScript resource files. It is typically
used as a resource file type plugin, referenced from resourceFileTypes
in project.json, while another plugin (such as ilib-loctool-json or
ilib-loctool-javascript) extracts strings from source files.
This plugin does not read existing JavaScript resource files from disk; it only generates them during localization.
Configuring the Plugin
Standard Settings
To use this plugin, reference it from the resourceFileTypes setting in
your project.json. The key names the source file type whose output
should be delegated to this plugin. For example, to write JavaScript
files for strings extracted from JSON:
{
"resourceFileTypes": {
"json": "ilib-loctool-javascript-resource"
},
"plugins": [
"ilib-loctool-json",
"ilib-loctool-javascript-resource"
]
}You can also set resourceFileTypes.javascript when the
ilib-loctool-javascript extraction plugin is in use.
Custom Settings
The plugin reads formatting and output-path settings from your
project.json settings object.
settings.javascript
- header: text placed before the JSON object in each output file. May
include locale placeholders such as
[localeUnder]that are replaced with the target locale. Default isilib.data.strings_[localeUnder] =. - footer: text placed after the JSON object. Default is
;\n. - template: path template used to determine the output file path when
an extraction plugin delegates output to this plugin. The template
supports the same bracket substitutions as other loctool plugins
(for example
[locale],[localeDir],[dir],[filename]). When set, the output path is computed from the source file path and target locale rather than fromresourceDirsalone. - extension: file extension for output files when no
templateis used. Default is.js.
settings.JavaScriptResourceFile
- prefix: optional text prepended before the header in each output file. Useful for import statements or other boilerplate that should appear at the very top of the file.
Example configuration when delegating from the json plugin:
{
"resourceFileTypes": {
"json": "ilib-loctool-javascript-resource"
},
"settings": {
"json": {
"outputSourceLocale": true,
"mappings": {
"**/strings.json": {
"template": "resources/[localeDir]/strings.json"
}
}
},
"javascript": {
"template": "resources/[locale].js",
"header": "// THIS FILE IS AUTOGENERATED. DO NOT EDIT MANUALLY.\n",
"footer": "\n// END OF FILE\n"
}
}
}Source Locale Resource Files
When this plugin writes a resource file for the project's source locale, it outputs the source string for each resource, even when the source and target text are the same. For target locales, it only includes strings whose translation differs from the source.
Whether a source-locale file is created at all is controlled by the extraction plugin that supplies resources to this plugin, not by this plugin itself. For example:
settings.json.outputSourceLocalewhen usingilib-loctool-jsonsettings.javascript.outputSourceLocalewhen usingilib-loctool-javascript
When enabled, the extraction plugin populates source-locale resources during localization; this plugin then formats and writes them like any other locale.
License
Copyright © 2019, 2021, 2026 JEDLSoft
This package is released under the Apache License, Version 2.0. The full license text is available in the LICENSE file in the ilib-mono repository on GitHub.
Release Notes
See CHANGELOG.md.
