Installation
npm install web-modules-utils
Webpack
All parameters are optional.
// webpack.config.js moduleexports = ;
Recommended minimal setup:
moduleexports = ;
Karma
// karma.conf.js
module.exports = function(config) {
var webpackConfig = require('web-modules-utils/utils/webpack').createConfig({
test: true,
skipGenerateLoaders: true,
simpleStyles: true
});
config.set(require('web-modules-utils/utils/karma').createConfig(webpackConfig));
};
Initial configuration
; ;
After that application may access configuration at any time:
;console;
Skins
;; // this file is generated by Webpack utility // Step 1. Set the brand and all other configuration (langage, etc.); // Step 2. Set the loader; // Step 3. Load skin, promise is returned, but it's optional to handle it;
Localization
Where should I store localized strings?
The root namespace for all localization files is src/app/lang
. All strings are grouped by relevance into packages.
How to include localization?
Boilerplate v2.0
You need to include localization only once before you bootstrap the entire application:
;; // this file is generated by Webpack utility // Step 1. Set the language and all other configuration (brand, etc.); // Step 2. Set the loader; // Step 3. Load strings;
Boilerplate v1.0 (Service Web)
Always include en_US
version of file. Url of the file will be dynamically rewritten during runtime.
var lang = ;
How to use localized strings?
Use the translate
function after strings were loaded:
;;
What is the structure of strings file?
The structure is a simple object exported as usual:
/** @namespace SOME_NAME_SPACE */ ALERT: "Alert" CONFIRMATION: "Confirmation" // ICU Message Format is used to tokenize the string MF_TEST: "You have received {NUM, plural, one{# call} other{# calls}} today \ Much wow, such new line" TOKENIZED: "A string with {TOKEN}" // If the same token can have different value in different brands COMPANY_NAME: 0: 'WhiteLabel' 1210: 'RingCentral' 2222: 'SomethingNew' ;
Please note that SOME_NAME_SPACE
is used in conjunction with getStrings()
:
;console; // will output Confirmation