Resource Strings and Localization

Tags: 311 views 0

How to add, override, and use different resource strings to customize the Order Website.

Overview

By convention, Atomia Order Website (Atomia Store) uses the App_GlobalResources\Common.resx file and derived theme files and translations for all changeable resource strings and translations except some validation messages, which are located in CustomerValidation.resx.

File Structure

An example file structure with themes and translations:

App_GlobalResources/
    MyTheme/
        MyThemeCommon.resx
        MyThemeCommon.de-DE.resx
        MyThemeCustomerValidation.resx
        MyThemeCustomerValidation.de-DE.resx
    Common.resx
    Common.de-DE.resx
    CustomerValidation.resx
    CustomerValidation.de-DE.resx

The example above has the default English resource strings in the resx files without language code, and default German localization in the *.de-DE.resx files.

The theme resource files must be located in a directory with the same name as the theme, and must also be prefixed with that name, MyTheme in this example.

Keep in mind

Only the theme specific files should be changed when implementing a custom theme.

Adding or Overriding Default Resource Strings

When you start a new theme, empty resource files are added to the theme for all default (English) and localized resxfiles that are available in the Default theme. You can use these files to add your own resource strings or override resource strings from the Default theme.

Keep in mind

You should only ever add resource strings to your theme resx files that are not available in the Default theme files, or that you want to override. Just adding the same content as in the Default theme resx files means you will not get the benefits of any spelling corrections or other improvements to the Default files.

Useful tip

It is possible to translate the country names that are listed in a drop-box on the Account step of the order flow. It is done the same way as it is done in the Billing User Panel by adding the new translation entry in the appropriate Atomia Order Website resx file.

Special Resource String

Some resource strings in Common.resx and derived files have a specific Name or Value format. These are annotated with comments in the Common.resx file in the Default theme.

E.g. language names are located via Name keys on the form <LanguageTag>_name and <LanguageTag>_shortname: EN_nameEnglish, EN_shortnameEN, FR_nameFrench, FR_shortnameFR etc.

Using Resources in Views

The recommended way of using resources from Common.resx in views is to use the @Html.CommonResource, @Html.CommonResourceRaw and @Html.CommonResourceJs HTML-helpers, which will output escaped, unescaped and JavaScript expression ready strings respectively. This will automatically locate the string Name in the correct resxfile, Default or from the theme. The HTML-helpers are defined in Atomia.Store.WebBase.HtmlHelpers.CommonResourcesHelper and are implicitly imported in all views by default.

Example usage:

@Html.CommonResource("AccountTitle")

JavaScript objects or JSON available via the Atomia namespace should also have any relevant properties already translated before being sent from or generated by the server, e.g. product names and descriptions.

Using Resources in .NET Code Via IResourceProvider

The recommended way of using resources in backend .NET code is to use the Atomia.Store.Core.IResourceProvider. It has a default implementation Atomia.Store.WebBase.Adapters.ResourceProvider that fetches resources from Common.resx and related localization and theme files.

Was this helpful?