Skip to content

Commit

Permalink
Merge pull request wikimedia#171 from wikimedia/169
Browse files Browse the repository at this point in the history
Documentation update
  • Loading branch information
amire80 authored Jul 25, 2018
2 parents 8f38bc4 + 5909a05 commit 2ee4e69
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ It is possible to switch to another locale after plugin is initialized. See belo
$.i18n({
locale: 'he' // Locale is Hebrew
});
$.i18n( 'message_hello' ); // This will give the Hebrew translation of message key `message_hello`.
$.i18n( 'message-hello' ); // This will give the Hebrew translation of message key `message-hello`.
$.i18n().locale = 'ml'; // Now onwards locale is 'Malayalam'
$.i18n( 'message_hello' ); // This will give the Malayalam translation of message key `message_hello`.
$.i18n( 'message-hello' ); // This will give the Malayalam translation of message key `message-hello`.
```

## Message Loading
Expand Down Expand Up @@ -230,8 +230,8 @@ It is also possible to refer messages from an external URL. See below example
```javascript
$.i18n().load( {
en: {
message_hello: 'Hello World',
message_welcome: 'Welcome'
message-hello: 'Hello World',
message-welcome: 'Welcome'
},
hi: 'i18n/messages-hi.json', // Messages for Hindi
de: 'i18n/messages-de.json'
Expand All @@ -243,18 +243,18 @@ Messages for a locale can be also loaded in parts. Example
```javascript
$.i18n().load( {
en: {
message_hello: 'Hello World',
message_welcome: 'Welcome'
message-hello: 'Hello World',
message-welcome: 'Welcome'
}
} );

$.i18n().load( {
// This does not remove the previous messages.
en: {
'message_header' : 'Header',
'message_footer' : 'Footer',
// This will overwrite message_welcome message
'message_welcome' : 'Welcome back'
'message-header' : 'Header',
'message-footer' : 'Footer',
// This will overwrite message-welcome message
'message-welcome' : 'Welcome back'
}
} );
```
Expand Down Expand Up @@ -294,7 +294,10 @@ It is also possible to have the above li node with fallback text already in plac
The framework will place the localized message corresponding to message-key as the text value of the node. Similar to $('selector').i18n( ... ).
This will not work for dynamically created elements.

Note that if data-i18n contains html markup, that html will not be used as the element content, instead, the text version will be used. $.fn.i18n is always about replacing text of the element. If you want to change the html of the element, you may want to use: ```$(selector).html($.i18n(messagekey))```
Note that if data-i18n contains html markup, that html will not be used as the element content, instead, the text version will be used. But if the message key is prefixed with `[html]`, the element's html will be changed. For example ```<li data-i18n="[html]message-key">Fallback html</li>```, in this if the message-key has a value containing HTML markup, the `<li>` tags html will be replaced by that html.


If you want to change the html of the element, you can also use: ```$(selector).html($.i18n(messagekey))```

Examples
========
Expand Down

0 comments on commit 2ee4e69

Please sign in to comment.