LangService is Solstice's mechanism for seperating the content of HTML pages from their structure, and for allowing a wide degree of internationalization. In every app you write on the Solstice framework, you should strive to have every bit of content that will be displayed to the user entered into your LangFile XML files.
LangService API
LangService is used in Views to get text for the current language of your Solstice install. The strings are broken in the 4 categories: messages, errors, help, and button data. Check out the pod for a full listing of what LangService offers.
Perl
use Solstice::LangService;
my $lang_service = Solstice::LangService->new();
my $content = $lang_service->getString('key_name');When creating a button, you can use LangService to get the label and the title of the button:
Perl
my $button = $button_service->makeButton({
label => $lang_service->getButtonLabel('button_name'),
title => $lang_service->getButtonTitle('button_name'),
action => 'button_action',
});You can also pass variables into LangService strings:
Perl
my $time = $lang_service->getString('current_time', {time => $current_time});This would fill out a LangSerivce entry such as:
XML
<str name=
"current_time"
>The current time is
<!-- sol_var name=time -->.
</str>
Example LangFile XML
The XML for LangService is stored in xml files by language code. English is in lang/en.xml, German in lang/de.xml, and so on. All content should be in CDATA blocks. The entries in the XML files can be manipulated using Majere.
XML
<i18n><errs>
<err name=
"error_name"
><![CDATA[Example Error]]></err>
</errs>
<msgs>
<msg name=
"message_name"
><![CDATA[Example Message]]></msg>
</msgs>
<strs>
<str name=
"string_name"
><![CDATA[Example String]]></str>
</strs>
<hlps>
<hlp name=
"help_name"
><![CDATA[Example Help]]></hlp>
</hlps>
<btns>
<btn name=
"button_name"
title=
"Button Title"
><![CDATA[Button Label]]></btn>
</btns>
</i18n>
Using Lang Strings in Your Templates
Any string you specify in your lang file can be used by any template in that application. For example, using the example lang file above you could go into your view and add the following:
Perl
my $lang_service = $self->getLangService();
$self->setParam('my_string', $lang_service->getString('string_name'));You would then have to open up the corresponding template and add in the template variable.
HTML
<!-- sol_var my_string -->
We can skip the first step completely. Simply adding a template variable that corresponds to the string name in the lang file will do the trick. Note that instead of using sol_var we use the special phrase sol_lang:
HTML
<!-- sol_lang string_name -->