Soluling home   Document home

JavaScript and TypeScript Localization and Internationalization

JavaScript and TypeScript Localization and Internationalization

JavaScript (Wikipedia) is a very popular scripting language used in browsers and servers. TypeScript (Wikipedia) is an object-oriented and strongly types superset of JavaScript. Recently you hardly ever use plain JavaScript, but you use some JavaScript library or framework. Soluling supports all major JavaScript libraries and frameworks that include support for internationalization:

Plurals in JavaScript and TypeScript

Standard JavaScript does not have any printf kind of function. Most applications use sprintf function (sprintf.js). It is not plural enabled, but fortunately, Soluling contains a plural enabled Plural.pluralSprint function for JavaScript.

If you use standard sprintf function, you might have something like this.

str = sprintf("%d files",  count);

Replace "%d files" with "%d file;%d files". The modified code is

str = Plural.pluralSprintf("one;%d file;other;%d files", count, count);

Plural.pluralSprintf function is found from <data-dir>\Library\JavaScript\plural.js. There is a TypeScript version in <data-dir>\Library\TypeScript\plural.ts.

See <data-dir>\Samples\HTML\Plural sample.

Samples

<data-dir>\Samples\HTML contains following samples:

Directory Description
Driving A simple driving time calculator application. Uses JavaScript.
Plural A sample that shows how to use plural messages. Uses JavaScript.
Sport A static HTML page that contains images.

Whenever a samples uses JavaScript files (.js) there are also corresponding TypeScript files (.ts).

Note! You can find Angular samples here, Rect samples here, Vue samples here, and Svelte samples here.