img1

Internationalization is a design process that ensures a product (usually a software application) can be adapted to various languages and regions without requiring engineering changes to the source code. Think of internationalization as readiness for localization. Internationalization can save significant expense, time, and headaches for everyone involved. Sometimes written as “i18n”, internationalization evolved from a growing demand for multilingual products and applications. Today we will be diving into the design considerations for APEX code that accommodates multi-language, multi-currency and multi-locale considerations.

Benefits of Internationalization

  • Improved code and architecture, leading to maintenance consistency
  • Single, internationalized source code for all versions of the product
  • Adherence to international standards, which leads to universal comprehension
  • Easier adaptation of software applications (or other content) to multiple locales
  • Careful and pragmatic use of text variables

Ways we can Internalize

  1. Translation Workbench
  2. Custom Labels

Translation Workbench

The translation workbench allows you to create translations for the customizations you’ve made to your Salesforce.com organization. Everything from custom picklist values to custom fields can be translated so your global users can use all of Salesforce.com in their language.

If you want to use the translation workbench, you need to enable it. Enabling the workbench makes some changes to your Salesforce.com organization:

  • Picklist values must be edited individually. This means you can’t mass edit picklist values, though you can still mass add new values.
  • When picklist values are sorted alphabetically, the values are alphabetical by the organization’s default language.
  • Reports have a language drop down on the filter criteria page when any filter criteria uses the “starts with”, “contains” or “does not contain” operators.
  • Import files have a language drop down and all records and values within the import file must be in that language.
  • Web-to-Lead and Web-to-Case have a language drop down before you generate the HTML.
  • All rules and setup data must be entered in the organization’s default language
  • Once enabled, it can be disabled upon a single click

Considerations for Updating Translated Terms

Translators are responsible for keeping the translated terms updated. When translated components change, the translated value becomes obsolete. For example, say you enter a translation for an error message on a lookup filter. Later, you edit the lookup filter and change the error message. When you go into the Translation Workbench and view the message translation column, it still shows the translation for the old error message and the checkbox in the Out of Date column is selected.

Custom Labels

Custom Labels are custom text values, up to 1,000 characters, that can be accessed from Apex Classes or Visualforce Pages or lightning components. If Translation Workbench has been enabled for your organization, these labels can then be translated into any of the languages salesforce.com supports. This allows developers to create true multilingual apps by presenting information to users - for example, help text or error messages - in their native language.

Syntax for custom label

1
2
3
4
// In Apex use 
System.debug(System.Label.LabelName)
//In Visualforce page
<apex:outputLabel value="{!$Label.LabelName}" />

Overriding Principals

By definition, do not require the programmer to know the details of every language or locale that you plan to support.

Dates and Times

  • Do not rely on a specific date or time format (e.g., MM/dd/yyyy or dd/MM/yyyy) anywhere
  • Never parse a string for date formats unless the string is generated by an external process. In that case, make the parsing format explicit.
  • Do not use Strings as dates.
  • Unless there is a reason to capture dates themselves (e.g., birthdays), use datetimes.

Picklists

  • Be aware of the difference between getValue and getLabel.
    • getValue Returns the value of this item in the picklist.
    • getlabel Returns the display name of this item in the picklist.
    • conclusion, the label returns the translated value and the value returns the defined value in the field. Rely on getValue for internal processes, and getLabel for presentation.

Object Names and Field Labels

  • Rely on “describe” information or, $ObjectType notation
    • {!$SobjectType.Opportunity.Fields.Name.Label}

X-Localization SObjects

When you turn on Translation Workbench, you get new objects for the following objects all suffixed by “Localization”.

  • RecordTypeLocalization
    • Represents the translated value of a label for a record type when the Translation Workbench is enabled for your organization.
  • Search for objects with suffix localization on Developer Doc Site

Record Types

  • Use the DeveloperName, not the Name of the Record Type. Matter of fact, you should try to use the DeveloperName, since its less susceptible to change as well.

Encoding

  • Since you have no control over what characters a translator will use, make sure to use HTMLENCODE, JSENCODE and JSINHTMLENCODE liberally in any literal HTML/JS your Visualforce pages.

Multiple Currencies

International organizations can use multiple currencies in opportunities, forecasts, reports, quotes, and other currency fields. The administrator sets the “corporate currency,” which reflects the currency of the corporate headquarters. The administrator also maintains the list of active currencies and their conversion rates relative to the corporate currency. The active currencies represent the countries in which the organization does business. Only active currencies can be used in currency amount fields.

Key Terms

  • Corporate Currency
    • It is the currency in which a company reports revenue, it is the primary currency for the organization.
  • Personal Currency
    • It is the default user currency. It can be accessed on the User’s record.
  • Record Currency
    • Specifies the currency type on the record for amounts.
  • CurrencyISOCode
    • It contains the string representation of the currency ISO code associated with currency values in the object.
  • DefaultCurrencyISOCode

    • It is attached to the User object, which indicates the default currency for a user.

      Usages

  • Check whether organization as MultiCurrency enabled

    1
    2
    
    Boolean isMultiCurrencyOrg = UserInfo.isMultiCurrencyOrganization();
    System.debug('MultiCurrencyOrg-' + isMultiCurrencyOrg);

    Implications

  • Once a currency is added to the list of the organization supported currencies, it cannot be deleted from the administrator’s list of currencies, even when it is deactivated.

  • A deactivated currency is not visible to end-users, but remains visible to administrators.

  • After enablement, all currency field displays the ISO Code of the currency before the amount.

  • Upon enablement, all records are stamped with a default currency code with the requested currency.

  • Once enabled, it can’t be disabled.

Technical Impacts

  • SOQL
    • Selecting currency fields using the SELECT keyword
    • Use convertCurrency() in the SELECT statement of a SOQL query to convert currency fields to the user’s currency.
    • Filtering using WHERE keyword
    • We cannot use the convertCurrency() function in a WHERE clause, use the following syntax to convert a numeric value to a user’s currency. If we do not put the ISO code the numeric value is used instead of the comparative value. SELECT id,Name FROM Opportunity WHERE Amount > USD5000
    • Aggregate functions
    • if a query includes a GROUP BY or Having clause, any currency data returned by using methods such as SUM() or MAX() is in the organization default currency. We cannot use convertCurrency() here.
    • You can’t use ISO_CODE value to represent a value in a particular currency, such as USD, when you use an aggregate function. For example, the following query doesn’t work. SELECT Name, MAX(Amount) FROM Opportunity GROUP BY Name HAVING MAX(Amount) > USD10000
    • You can’t use convertCurrency() with ORDER BY. Ordering is always based on the converted currency value, just like in reports.
  • Custom Formula Fields
    • These fields are not tied to any particular currency. If the result of a formula field is a currency amount, it displays in the currency of the associated record. This is also true for cross-object formula’s that reference merge fields with different currencies and formula’s in workflow rules and approval processes.
    • However, note that workflow rules and approval processes that use filters instead of formula convert all currency values to the corporate currency.
  • Reports, ListViews, Workflow/Approval Criteria
    • Amount runs in a user’s currency unless the currency ISO Code is specified in the filter criteria.
  • Web to Lead/Case
    • Add the currency ISO Code field to web forms if the amount for the fields are included to ensure records created contain the correct currencies.
  • Data Migration & Integration
    • Specify the currency ISO Code on records for import otherwise, they will default to the personal currency of record creator.
  • Advanced Currency Management
    • Evaluate roll-up summary fields that might be affected
    • Consider alternative solutions, such as Apex Triggers

Supported Currency Objects

  • CurrencyType

    • Represents the currencies used by an organization for which the multicurrency feature is enabled. Use this object to define the currencies your organization uses.
    • Special Rules
    • This object is not available in single-currency organizations.
    • You need the “Customize Application” permission to edit this object.
    • Your client application can’t delete this object.
    • Customer Portal users can’t access this object.

      User Locale

      Locales determine the display formats for date and time, user’s names, addresses, and commas and periods in numbers. The start day of the week for calendars varies per locale. For single-currency organizations, locales also set the default currency for the organization when you select them in the Currency Locale picklist on the Company Information page.

APEX Locale Support

Get the user local language from logged in user SELECT LanguageLocaleKey FROM User WHERE Id = :UserInfo.getUserId()]. Use Language tag in Visualforce to support use locale.

1
2
<!-- userLocal is the property whose value you'll get from a query -->
<apex:page language="{!userLocal}"> 

Use the following snippet to get the user locale in lightning/aura components.

1
var locale = $A.get("$Locale.language");