官术网_书友最值得收藏!

Localization and translation

It is important to take localization and translation into consideration from the beginning as it can become difficult and costly to apply it later. Fortunately, the platform can do a lot of work for you.

Localization

When using the native user interface, it automatically formats the values of the numeric and date fields according to the Locale field on the user profile. Visualforce pages using the apex:outputField and apex:inputField components will automatically format values, and outputting local sensitive values in any other way will need to be handled manually in your Apex Controller code or in your JavaScript code.

Tip

It's not always possible to use the Visualforce apex:inputField and apex:outputField tags as described earlier in this chapter. For example, if the information you are displaying is not contained within a Custom Object field, but in some calculated view state in your Apex Controller. The format methods on various type classes such as Date, DateTime, and Decimal, can be used to generate a formatted string value that you can bind to on your pages. You can also determine the users' ISO locale code via UserInfo.getLocale().

Translation

Literal text entered when defining components such as Custom Objects, fields, and layouts are automatically available to the Salesforce Translation Workbench tool. However, literal text used in the Apex code and Visualforce pages need special attention from the developer through the use of Custom Labels.

It is important to avoid the concatenation of Custom Label values when forming messages to the end user, as it makes it harder for translators to understand the context of the messages and if needed, resequence the context of the message for other languages. For example, take the message The driver XYZ was disqualified. The bad practice is:

String message = Label.TheDriver + driverName + Label.WasDisqualified;

The good practice is as follows:

String message = String.format(Label.DriverDisqualified, new String'' " driverName");

The DriverDisqualified Custom Label will be defined as follows:

Translation

Tip

When creating Custom Labels, be sure to pay attention to the Protected checkbox. If you uncheck it, end users can reference your labels, which you might want to consider if you wish them to reuse your messages, for example in custom Email Templates or Visualforce pages. However, the downside is that such labels cannot ever (currently) be deleted from your package as your functionality changes.

Finally, remember that in Visualforce you can utilize apex:ouputField within apex:apex:pageBlockSection and the field labels will automatically be rendered next to the fields on the page.

主站蜘蛛池模板: 肃宁县| 苏州市| 乐都县| 延庆县| 抚宁县| 彩票| 古浪县| 雷波县| 龙川县| 济阳县| 集安市| 苍溪县| 松原市| 阳西县| 凤山市| 仲巴县| 建瓯市| 永靖县| 阳新县| 扎鲁特旗| 工布江达县| 嘉峪关市| 大连市| 平舆县| 岳阳市| 兴安盟| 浦东新区| 万宁市| 大新县| 连山| 德阳市| 铁岭县| 涿州市| 宜君县| 齐河县| 晋州市| 麦盖提县| 镇康县| 宝应县| 清徐县| 且末县|