Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zewa666/knockout-i18n
A module + binding providing i18n support for Knockout
https://github.com/zewa666/knockout-i18n
Last synced: about 12 hours ago
JSON representation
A module + binding providing i18n support for Knockout
- Host: GitHub
- URL: https://github.com/zewa666/knockout-i18n
- Owner: zewa666
- Created: 2013-09-08T11:27:42.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-08T11:47:37.000Z (about 11 years ago)
- Last Synced: 2023-04-06T14:20:36.499Z (over 1 year ago)
- Language: JavaScript
- Size: 496 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Knockout-i18n
=======================This is a custom binding and module providing i18n support for KnockoutJS.
The idea is to collect in advance all the translation options from a backend (this example uses a simple PHP file), and
use Knockout features to bind translations to elements or directly to code.
All translations are provided as a big JSON object, therefore usage is quite simple (see example)The provided example also implements a simple language switcher, which builds on the update method feature of custom bindings.
Bindingname is declared as tk_i18n to ensure no clash with other possible bindings.Usage
-----Please inspect the whole example to get an idea how it works.
For a kickstart you should do following- edit the file backend/Locales.php to provide your locales and translations
- set the current locale by calling the setLocale method, providing the locale as parameter
- for data-binds use the following binding
```javascript
/* simple translation no extras */
"tk_i18n: 'YOUR TRANSLATION KEY'"/* prefix and sufix added */
"tk_i18n: { text: 'YOUR TRANSLATION KEY', prefix: 'YOUR PREFIX', sufix: 'YOUR SUFIX' }"
```
- for usage via code
```javascript
// obtain reference of the i18n module either in define or by require
var i18n = require('js/tk_i18n');// access the locale translation holder and choose your key
i18n.locale().YOURKEY
```
Dependencies
------------- jQuery
- Knockout
- RequireJSNew Features Log
----------------- Added support for C# like string.format(), so you can now create translations with templates
```javascript// See in example in testModel.js
i18n.locale().msgTotalAmount.format(self.amountCar() + self.amountBeer());
```