Localizing Template Resource Bundles
Template resource bundles hold static content for localization. They are stored for
each cartridge within the /templates/resources
directory. Messages from the
bundles are accessible to all templates of the corresponding cartridge via the
msg()
method, available in the dw.web.Resource
class.
These properties files have already been created for you in the SiteGenesis application. They each contain a list of text that pertains to its corresponding object (template or form) ). They are organized as a single properties file per top level directory.
Resource.msg()
function based
on the given locale. If you are using the dw.net.Mail
class to send messages, the LocaleID set through
Template.setLocaleId
or the constructor
Template(Template,LocaleID)
is used to look up the
template resource before the locale linked to the current request.
Account Example
For example, account.properties, which lists the text in the minicartcontent.isml template, looks like this:
##############################################
# ISML Directory: account/addressbook/
##############################################
editaddress.editaddress=Edit Address
editaddress.addaddress=Add Address
editaddress.defaultaddress=Default Address
editaddress.makedefaultaddress=Make Default
For any text to be included in the storefront using this methodology, you must create a new line within the corresponding language-specific properties file. These language files are named to correspond to the file directory of the language snippet to be used. Each text snippet has a unique key (unique across resource bundle files).
Comments
Comments are preceded by a # character.
For example, in the account.properties file, the text list is separated by the sub directories within the top level directories.
##############################################
# ISML Directory: account/
##############################################
accountoverview.welcome=Hello
accountoverview.welcome2=, Welcome Back
accountoverview.not=Are you not
accountredirect.title=Redirect
accountredirect.permanent=This account has been permanently removed. You can attempt to login with another account or create a new account by going to the
accountredirect.accountlogin=login page.
account.forbidden=This page has timed out. You must close the window and login to continue.
account.createnew=Create Account
account.editaccount=Edit Account
##############################################
# ISML Directory: account/addressbook/
##############################################
editaddress.editaddress=Edit Address
editaddress.addaddress=Add Address
editaddress.defaultaddress=Default Address
editaddress.makedefaultaddress=Make Default
Properties with the sub directory would be separated, as shown previously.
Form Example
The following is an example of using properties within a German version of a form (forms/default/creditcard_de.xml - forms.properties):
##############################################
# Template name: forms/default/creditcard_de
##############################################
creditcard.visa=Visa
creditcard.mastercard=Mastercard
creditcard.amex=Amex
creditcard.discover=Discover
creditcard.cvn=CVN
creditcard.savecard=AuοΏ½er Dieser Kreditkarte
- account_en_GB.properties
- account_en_US.properties
- account_en.properties