Multi Language Usage - js-lib-com/wood GitHub Wiki
Usage example for project with multiple languages.
Language - or multiple languages - should be declared on project descriptor. Language value format is usually ISO two-letter code but language with country code is supported. For example both en
and ro-RO
are valid language values. See language format.
For multiple languages declaration order maters: first language is considered the default one. All files without language variants are considered as default language.
WOOD tools will generate a complete sub-site for every language defined in project descriptor. Sub-site names are exactly as declared, en and ro-RO. The same goes for lang attribute from HTML element.
- project.xml
<project>
<!-- project language declaration -->
<language>en, ro-RO</language>
</project>
Lets consider a page with a reference to a string variable - @string/title
.
- page/index/index.htm
<body>
<!-- string variable reference -->
<h1>@string/title</h1>
</body>
On project assets we have string definition files. File without variants is considered default language, in our case en. This is because on project descriptor first declared language is indeed en.
- asset/string.xml
<string>
<!-- string variable definition for English language -->
<title>Page Title</title>
</string>
Here is string definition file for Romanian language. If this language would not be declared on project descriptor, this string definition file would be ignored.
- asset/string_ro-RO.xml
<string>
<!-- string variable definition for Romanian language -->
<title>Titlu pagină</title>
</string>
WOOD tools produces two sub-sites, one for every language declared on project descriptor, see language declaration. In our case we have site/en and site/ro-RO sub-sites.
If a language is declared in project descriptor but there are no files with that language variant, WOOD tools uses the default language. So sub-site is generated even if language variant is not actually used on any file.
On first sub-site, sub-site name and lang attribute from HTML element are both en, exactly as declared on project descriptor.
- site/en/index.htm
<HTML lang="en">
<HEAD>
...
</HEAD>
<BODY>
<H1>Page Title</H1>
</BODY>
</HTML>
Second sub-site name and lang attribute are both ro-RO, as declared on project descriptor. Note also the page heading is loaded from string definition file asset/string_ro-RO.xml.
- site/ro-RO/index.htm
<HTML lang="ro-RO">
<HEAD>
...
</HEAD>
<BODY>
<H1>Titlu pagină</H1>
</BODY>
</HTML>
Last updated 9/8/2022.