{"_id":"webl10n","_rev":"3-51fc7e3516ae620580837fde1b28cba7","name":"webl10n","description":"internationalization and localization library","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"webl10n","version":"1.0.0","description":"internationalization and localization library","main":"l10n.js","scripts":{},"repository":{"type":"git","url":"https://github.com/fabi1cazenave/webL10n.git"},"keywords":["l10n","i18n"],"author":{"name":"Fabien Cazenave"},"license":"WTFPL","bugs":{"url":"https://github.com/fabi1cazenave/webL10n/issues"},"homepage":"https://github.com/fabi1cazenave/webL10n","gitHead":"5599c2eb7c5278200472255f02a7256d7f6f1139","_id":"webl10n@1.0.0","_shasum":"da1680c63cea81a01d0bc59e2f943a52eba770ed","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"fabi1cazenave","email":"fabien@cazenave.cc"},"maintainers":[{"name":"fabi1cazenave","email":"fabien@cazenave.cc"}],"dist":{"shasum":"da1680c63cea81a01d0bc59e2f943a52eba770ed","tarball":"https://registry.npmjs.org/webl10n/-/webl10n-1.0.0.tgz","integrity":"sha512-cEbXU5WqmYSdPYhh5PyTwGhye7urOE1EKanSZOiEnOHbVhqzLEAUXrpTiQf5iKWkwd01XRYPHsHlwgZvhQYX4g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFdxID6LnSl7LFNVFvZjXlNgM2FQZLC8U8Pnlf10qfWSAiAxmB8wuEX4j4gnj4qZGkXf0Ll8mUIC6UyJqLj42A7JUA=="}]}}},"readme":"webL10n is a client-side, cross-browser i18n/l10n library (internationalization / localization), designed with modern web applications in mind.\n\nUnlike other i18n/l10n libraries, webL10n supports:\n\n* declarative localization: elements with `l10n-*` attributes are automatically translated when the document is loaded;\n* named variables instead of printf-like `%s` tokens;\n* a simple and full-featured pluralization system;\n* server-less language negotiation (think of offline webapps);\n\nWe don’t focus on the gettext format: the bullet-proof `*.properties` format, used in Mozilla and GWT projects, is preferred — at least, by default.\n\nDemo: <http://fabi1cazenave.github.com/webL10n/> (outdated — feel free to submit a new one! ^^)\n\nThis library is also used by the FirefoxOS front-end (Gaia) with a different JavaScript API: a modern API for FirefoxOS/Gaia (with web standards in mind), a basic cross-browser one in webL10n (compatibility with IE6/IE7/IE8).\n\n[More information on the Wiki.](https://github.com/fabi1cazenave/webL10n/wiki)\n\nQuick Start\n-----------\n\nHere’s a quick way to get a multilingual HTML page:\n\n```html\n<html>\n<head>\n  <script type=\"text/javascript\" src=\"l10n.js\"></script>\n  <link rel=\"prefetch\" type=\"application/l10n\" href=\"data.ini\" />\n</head>\n<body>\n  <button data-l10n-id=\"test\" title=\"click me!\">This is a test</button>\n</body>\n</html>\n```\n\n* l10n resource files are associated to the HTML document with a ``<link>`` element;\n* translatable elements carry a ``data-l10n-id`` attribute;\n* l10n resources are stored in a bullet-proof ``*.ini`` file:\n\n```ini\n[en-US]\ntest = This is a test\ntest.title = click me!\n[fr]\ntest = Ceci est un test\ntest.title = cliquez-moi !\n```\n\n\nJavaScript API\n--------------\n\n`l10n.js` exposes a rather simple `document.webL10n` object.\n\n```javascript\n// Set the 'lang' and 'dir' attributes to <html> when the page is translated\nwindow.addEventListener('localized', function() {\n  document.documentElement.lang = document.webL10n.getLanguage();\n  document.documentElement.dir = document.webL10n.getDirection();\n}, false);\n```\n* `localized` event: fired when the page has been translated;\n* `getLanguage` / `setLanguage` method: get/set the ISO-639-1 code of the current locale;\n* `getDirection` method: direction (ltr|rtl) of the current language;\n* `get` method: get a translated string.\n\n```javascript\nvar message = document.webL10n.get('test');\nalert(message);\n```\n\nYou will probably use a gettext-like alias:\n\n```javascript\nvar _ = document.webL10n.get;\nalert(_('test'));\n```\n\nTo handle complex strings, the `get()` method can accept optional arguments:\n\n```javascript\nalert(_('welcome', { user: \"John\" }));\n```\n\nwhere `welcome` is defined like this:\n\n```ini\n[en-US]\nwelcome = welcome, {{user}}!\n[fr]\nwelcome = bienvenue, {{user}} !\n```\n\n\nAdvanced usage\n--------------\n\n### l10n arguments\n\nYou can specify a default value in JSON for any argument in the HTML document with the `data-l10n-args` attribute. In the last example, that would be:\n\n```html\n<p data-l10n-id=\"welcome\" data-l10n-args='{ \"user\": \"your awesomeness\" }'>Welcome!</p>\n```\n\n### @import rules\n\nIf you don’t want to have all your locales in a single file or if you want to\nshare strings between several pages, you can use CSS-like `@import` rules.\n\nMore information on the [Language Selection](https://github.com/fabi1cazenave/webL10n/wiki/Language-Selection) page.\n\n### Pluralization\n\nThe following strings might be gramatically incorrect when `n` equals zero or one:\n\n```ini\n[en-US]\nunread = You have {{n}} unread messages\n[fr]\nunread = Vous avez {{n}} nouveaux messages\n```\n\nThis can be solved by using the pre-defined `plural()` macro:\n\n```ini\n[en-US]\nunreadMessages = {[ plural(n) ]}\nunreadMessages[zero]  = You have no unread messages\nunreadMessages[one]   = You have one unread message\nunreadMessages[other] = You have {{n}} unread messages\n[fr]\nunreadMessages = {[ plural(n) ]}\nunreadMessages[zero]  = Vous n’avez pas de nouveau message\nunreadMessages[one]   = Vous avez un nouveau message\nunreadMessages[other] = Vous avez {{n}} nouveaux messages\n```\n\nHere, `unreadMessages` is an array and `{[plural(n)]}` points to the selected index.\n\n`plural()` returns zero | one | two | few | many | other, depending on `n` and the current language, as specified in the Unicode rules. If one of these indexes isn’t found, the `[other]` index will be used by default.\n\n\n### innerHTML\n\nBy default, we currently assume that all strings are applied as `textContent`.\nHowever, you can modify the `innerHTML` property with a simple rule:\n\n```ini\nwelcome.innerHTML = welcome, <strong>{{user}}</strong>!\n```\n\nWarning: this raises a few security questions that we haven’t addressed yet. In a future version we might:\n* sanitize the localized string before applying it as `innerHTML` (like in the PHP ``strip_tags`` method)\n* provide text-to-HTML methods (e.g. markdown) throught pseudo-properties, for example:\n\n```ini\nwelcome#text = welcome, {{user}}!\nwelcome#html = welcome, <strong>{{user}}</strong>!\nwelcome#mark = welcome, **{{user}}**!\n```\n\n\nFurther thoughts\n----------------\n\n### Media queries\n\nFor mobile apps, here’s what I’d like to do:\n\n```html\n<link rel=\"prefetch\" type=\"application/l10n\" href=\"data.ini\" />\n<link rel=\"prefetch\" type=\"application/l10n\" href=\"mobile.ini\"\n      media=\"screen and (max-width: 640px)\" />\n```\n\n### Multi-line strings\n\nMulti-line and wrapped strings aren’t supported at the moment. The *.properties way to extend a string on several lines is to use a backslash at the end of line… but there could be sharper/easier ways to handle that.\n\nYAML handles multi-line / wrapped strings nicely with the pipe and backslash operators, maybe we could reuse that in webL10n?\n\n\n### More structured syntax\n\nThere are cases where the entity has to be an array or a list (e.g. to handle plural rules), instead of a string. Currently we use the `entity[key]` notation but a more compact syntax could be supported as well.\n\nAlternatively, we could use a JSON- or YAML-like file format to handle the whole structure in a more modern way.\n\n\n### Logical expressions\n\nThe Mozilla l20n/LOL project introduces the concept of “expression”, which can be used to address most grammatical rules or some very specific situations.\n\nThe `plural()` macro above could be easily defined as an expression:\n\n```ini\nplural(n) = { n == 0 ? 'zero' : (n == 1 ? 'one' : 'other') }\n```\n\n\nBrowser support\n---------------\n\nTested on Firefox, Chrome, Opera and Internet Explorer 6 to 10.\n\n\nLicense\n-------\n\nBSD/MIT/WTFPL license. Use at your own risk.\n\n","maintainers":[{"name":"fabi1cazenave","email":"fabien@cazenave.cc"}],"time":{"modified":"2022-06-28T23:30:35.434Z","created":"2015-04-24T19:20:27.140Z","1.0.0":"2015-04-24T19:20:27.140Z"},"homepage":"https://github.com/fabi1cazenave/webL10n","keywords":["l10n","i18n"],"repository":{"type":"git","url":"https://github.com/fabi1cazenave/webL10n.git"},"author":{"name":"Fabien Cazenave"},"bugs":{"url":"https://github.com/fabi1cazenave/webL10n/issues"},"license":"WTFPL","readmeFilename":"README.md"}