This adds angular directives that allow you to perform seamless and advanced translations using TML from TranslationExchange.
npm install tml-angular
This adds angular directives that allow you to perform seamless and advanced translations using TML from TranslationExchange.
Learn more about TML
- AngularJS
- TranslationExchange account
You can get it from Bower
``sh`
bower install tml-angular
Or on NPM
`sh`
npm install tml-angular
example is for bower, replace bower_components if you put it elsewhere.
Make sure to include it after the angular script tag
angular.module('app', ['tml']);
angular.module('app', [require('tml-angular')]);
For best results, your angular app should start after the TML library has been initialized.
Remember to remove ng-app from your HTML and instead manually bootstrap the angular app, like in the following example:
tml.init({
key: "YOUR_KEY",
onLoad: function (app) {
angular.bootstrap(document, ['YOUR_NG_APP']);
}
});
#### As an element, with scope defined data
This expects a user key to be defined on the scope where this directive is used.
$scope.user = 'John Doe';
#### As an attribute, with scope defined data
#### As an element, with custom token associations
You can pass angular expressions in attributes wherever you use tml-tr
$scope.stats = { visit_times: 240 };
#### As an element, using a values object
Instead of using scope names, it is possible to pass an object with token values, as custom as you make it
$scope.userParams = { name: 'Steve', age: 28, birthday: true };
Note: this cannot be combined with scope parameters
use either custom attributes + scope variables or a values object, not both.
#### Phrase description ####
The description of a phrase is not mandatory, but it should be used in cases when the label alone is not sufficient enough to determine the meaning of the sentence being translated. As a general rule, you should always provide description to words, phrases and sentences that are only meaningful within a specific context. TML uses label and description together to create a unique key for each phrase. The description serves two purposes: it creates a unique key for each label and it also gives a hint to the translators for the context in which the label is used.
#### Translate input placeholders and other special fields
There's a global function for translating labels, called trl(template, values), it has access to the scope it runs from, so the values object is optional
You can also use trl as a filter, this is recommended for simple strings only, because filter doesn't have access to the scope by default.
Passing parameters is possible with filters:
Use the surrounding scope (pass the this keyword):
{{ "Hello {user}" | trl:this }}
Pass a custom values object:
{{ "Hello {user}, this is your {num} visit" | trl:{ user: logged_in_user, num: visitCounter } }}
The cool thing about filters is how easy it is to combine them (but otherwise - prefer to use the other options):
There are a few useful properties exposed on the $rootScope:
currentLocale - Language specific stylesheets
Dynamically replace the stylesheet based on locale of the language
Show a block for a specific locale
isRtl` - Right to left stylesheets
Dynamically replace the stylesheet based on direction of the language
Links
==================
* Register on TranslationExchange.com: http://translationexchange.com
* Read TranslationExchange's documentation: http://docs.translationexchange.com
* Follow TranslationExchange on Twitter: https://twitter.com/translationx
* Connect with TranslationExchange on Facebook: https://www.facebook.com/translationexchange
* If you have any questions or suggestions, contact us: feedback@translationexchange.com
Copyright and license
==================
Copyright (c) 2016 Translation Exchange, Inc
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.