Hi CC,
The standard mechanism for doing this in Episerver uses XML files placed in the /lang folder to configure the strings and the LocalizationService to retrieve them. Each XML language file can have any number of languages (though it makes sense to keep things to 1 file per language for ease of translation) and you can have any number of XML files which can have any name you consider appropriate (as long as it ends with a .xml).
The basic structure using your example above would be:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <languages> <language name="English" id="en"> <myheader>my English translation</myheader> </language> </languages>
Though, once you're inside the <language> node, your XML structure is up to you and can be nested. You can then use the translation as follows:
<h1>@LocalizationService.Current.GetString("/myheader");</h1>
This is documented here:
https://world.episerver.com/documentation/developer-guides/CMS/globalization/Localization-service/
Thanks @Paul
Apologies for this next elementary question but this is my first EPi project so I'm unfamiliar with most of the structure.
It sounds like I need to create a new i18n.xml file and in that file I'll have the xml descriptor and a <languages/> and a <language/> tag(s).
So, question is, how do i get EPi to pick up on this language file?
Do I ...
Register it via initialization module?
Include it in the web.xml?
Make a reference to my i18n file in web.xml?
Thanks again
CC
Hi CC,
If you put the files in the /lang folder in the root of your site, you shouldn't need to do anything else to get them to be picked up as that location is registered by default.
If you need to add your translation files elsewhere then you can either use the localization node of the episerver.framework section of your config or you can create an initialization module to register that location and it's really your choice which you choose. Personally I'd go for the config option unless you're writing an add-on or similar.
Looking to create i18n files w/ key value pairings for english and french and display on their appropriate channels...
example:
my-french-i18n.file
-----------------
my.header = my french translation
my-english.i18n.file
------------------
my.header = my english translation
Then in the razor file, something like
------------------
i18n['my.header']
or
i18n.getValueByKey('my.header')
Cant seem to find docs on this aywhere...
How does this work in episerver?
Can someone point me in the right direction?
Thanks,
CC