Confirmed users
60
edits
(Created page with "= Intro = This document is a tutorial on how to use L20n to localize your HTML web aplication. == Initial setup == We'll operate on an example of a very simple HTML5 document ...") |
m (Typo) |
||
| (10 intermediate revisions by one other user not shown) | |||
| Line 33: | Line 33: | ||
The last piece of the equation is to bind the HTML nodes to their respective localizable elements (called entities) by setting an ''l10n-id'' attribute on each node. | The last piece of the equation is to bind the HTML nodes to their respective localizable elements (called entities) by setting an ''l10n-id'' attribute on each node. | ||
main.lol: | |||
<page "Page"> | |||
<discussion "Discussion"> | |||
<edit "Edit"> | |||
HTML: | HTML: | ||
<html> | |||
<html> | <head> | ||
'''<link rel="resource" type="intl/l20n" href="./locales/main.lol" />''' | |||
</head> | |||
<body> | |||
<header> | |||
<nav> | |||
<ul> | |||
<li '''l10n-id="page"''' /> | |||
<li '''l10n-id="discussion"''' /> | |||
<li '''l10n-id="edit"''' /> | |||
</ul> | |||
</nav> | |||
</header> | |||
</body> | |||
</html> | |||
</html> | |||
With this change, we now have our document localizable! | With this change, we now have our document localizable! | ||
| Line 68: | Line 67: | ||
HTML: | HTML: | ||
<html> | |||
<html> | <head> | ||
'''<script type="text/javascript;version=1.8" src="./js/l20n-xml.min.js"></script>''' | |||
<link rel="resource" type="intl/l20n" href="./locales/main.lol" /> | |||
</head> | |||
<body> | |||
<header> | |||
<nav> | |||
<ul> | |||
<li l10n-id="page" /> | |||
<li l10n-id="discussion" /> | |||
<li l10n-id="edit" /> | |||
</ul> | |||
</nav> | |||
</header> | |||
</body> | |||
</html> | |||
== Pick a language == | == Pick a language == | ||
| Line 97: | Line 95: | ||
main-en-US.lol: | main-en-US.lol: | ||
<page "Page"> | |||
<page "Page"> | <discussion "Discussion"> | ||
<discussion "Discussion"> | <edit "Edit"> | ||
<edit "Edit" | |||
main-de.lol: | main-de.lol: | ||
<page "???"> | |||
<page "???"> | <discussion "???"> | ||
<discussion "???"> | <edit "???"> | ||
<edit "???" | |||
now we need to modify our HTML document to a) provide the list of available locales and b) instruct the document on where to find each locale file. | now we need to modify our HTML document to a) provide the list of available locales and b) instruct the document on where to find each locale file. | ||
| Line 115: | Line 109: | ||
HTML: | HTML: | ||
<html> | |||
<html> | <head> | ||
'''<meta http-equiv="Content-Language" Content="en-US, de">''' | |||
<script type="text/javascript;version=1.8" src="./js/l20n-xml.min.js"></script> | |||
<link rel="resource" type="intl/l20n" '''href="./locales/main-{{ locale }}.lol"''' /> | |||
</head> | |||
<body> | |||
<header> | |||
<nav> | |||
<ul> | |||
<li l10n-id="page" /> | |||
<li l10n-id="discussion" /> | |||
<li l10n-id="edit" /> | |||
</ul> | |||
</nav> | |||
</header> | |||
</body> | |||
</html> | |||
Now, the l20n framework will take the locales available for the document and sort them according to the user preference. In result the best locale out of the available ones will be picked and loaded. | |||
Now, the l20n framework will take the locales available for the document and sort them according to the user preference. In result the best locale out of the | |||
We now have a fully localized document! Whoa! | We now have a fully localized document! Whoa! | ||
| Line 147: | Line 138: | ||
HTML: | HTML: | ||
<html> | |||
<html> | <head> | ||
<script type="text/javascript;version=1.8" src="./js/l20n-xml.min.js"></script> | |||
<span style="color: green"><script type="text/javascript"> | |||
var ctx = document.l10nCtx; | |||
ctx.settings.locales = ['en-US', 'de', 'it']; | |||
ctx.settings.schemes = [ | |||
'./locales/<nowiki>{{ locale }}/{{ app }}/{{ resource }}</nowiki>.lol | |||
]; | |||
</script></span> | |||
<link rel="resource" type="intl/l20n" href="<span style="color: green">./locales/main-<nowiki>{{ locale }}</nowiki>.lol</span>" /> | |||
</head> | |||
<body> | |||
<header> | |||
<nav> | |||
<ul> | |||
<li l10n-id="page" /> | |||
<li l10n-id="discussion" /> | |||
<li l10n-id="edit" /> | |||
</ul> | |||
</nav> | |||
</header> | |||
</body> | |||
</html> | |||
</html | |||
or, for decoupled from the document and put into separate JSON manifest: | or, for decoupled from the document and put into separate JSON manifest: | ||
| Line 200: | Line 189: | ||
<head> | <head> | ||
<script type="text/javascript;version=1.8" src="./js/l20n-xml.min.js"></script> | <script type="text/javascript;version=1.8" src="./js/l20n-xml.min.js"></script> | ||
<link rel="manifest" type="intl/manifest" href="./locales/manifest.json"> | <span style="color: green"><link rel="manifest" type="intl/manifest" href="./locales/manifest.json"></span> | ||
<link rel="resource" type="intl/l20n" href="l10n:pontoon:core/editor" | <link rel="resource" type="intl/l20n" href="l10n:pontoon:core/editor" /> | ||
</head> | </head> | ||
<body> | <body> | ||