Localizing XQuery Messages
XQuery code within the Content Delivery application is often responsible for returning status, success, or error messages. When generating these messages, the XQuery module is responsible for consulting the appropriate language resource to pull the correct, localized message.
Content Delivery is capable of localizing content produced by XQuery. Only content that the user will see is internationalized. Other content, such as system logs, are left in English.
You can access the language resources using the "t" (for translate) function in the XQuery Util module. For example, you can request a language resource by name, which returns (in English) the string "Incorrect Credentials."
LiveContent-Util:t("login.fail", "")
You can also request a language resource by name, and specify the skin to load. This is usually only used when a $skin parameter is passed into the function that is requesting the language resource.
LiveContent-Util:t("login.fail", "navy.sea")
or
LiveContent-Util:t("login.fail", $skin)
When forming the response to an attempt to login, the session.xql module uses the following code:
declare function LiveContent-Session:login($user as xs:string, $passwd as xs:string) as node() {
if($user ne "") then (
if($user ne "guest" and xmldb:login("/db", $user, $passwd,true())) then (
let $save := session:set-attribute("loggedin", "true")
return
<result status="SUCCESS" action="login" sessionId="{session:get-id()}" user="{$user}"/>
) else (
<result status="FAIL" message="{LiveContent-Util:t("login.fail", "")}"/>
)
) else (
(: empty password? no username? :)
<result status="FAIL" message="{LiveContent-Util:t("login.empty", "")}"/>
)
};