JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Class: module:translations/js/api/I18n

Static routines for common translation tasks.

Version:
  • 16.3.1
Source:

Members

(static) Type :String

stable API

An enum of common translation categories. All translatable strings in the translation table must be rooted on one of the types below. If used consistently to build the keys of the translation table, the table will in the end look like:

Type:
  • String
Properties:
Name Type Description
Application String

For app-level metadata: App name, copyright notices, etc.

Page String

For the page tree and all components on a page

Entity String

For entities and fields

MainMenu String

For menus and sub-menus

Version:
  • 16.3.1
Source:
See:
Example

A sample of translation table when i18n types are used consistently

 "main-menu": {
   "homePage": "Home"
 }
 "entities": {
   "Sales" : {
     "name": "Sales",
     "revenue": {
         "name": "Revenue"
     }
   }
 }
 "pages": {
   "homePage": {
     "displayName": "Home",
     "button-123456678": {
       "displayName":
     }
   }
 }

Methods

(static) createTranslatable(i18nKey) → {translations/js/api/Translatable}

stable API

A factory method for instantiating Translatable. The i18n key passed into this method can be:

  1. The key of a currently existing translation, run-time or design-time
  2. A newly minted key for a non-existing translation; use I18n.key() to construct such keys
  3. The empty string. Creating empty-string translatables can be used to intialize fields with a Translatable whose value can be entered later
Parameters:
Name Type Description
i18nKey String

the key for the new translatable

Version:
  • 16.3.1
Source:
Returns:

the created translatable or undefined if the passed-in key was invalid

Type
translations/js/api/Translatable
Examples

Create a Translatable From a DT String

var displayNameNls = I18n.createTranslatable('componentsDt.createButtonDisplayText');

Create a Translatable From a Newly-Minted Key

var fieldNameNls = I18n.createTranslatable(I18n.key(I18n.Type.Entity, entity.getId(), field.getId(), I18n.Suffix.SingularName));

Create an Empty-String Translatable

var displayNameNls = I18n.createTranslatable('');

Create a Translatable From a Previously Serialized Translatable

// Reading a previously persisted translatable
var serializedDisplayName = model.data.displayName;
// De-serializing a translatable
var displayNameNls = I18n.createTranslatable(serializedDisplayName);

(static) key(type, …varArgs) → {String}

stable API

Builds an i18n key from the string tokens passed in.

The first parameter passed in must be one of the enum types listed in I18n.Type.

Parameters:
Name Type Attributes Description
type String

one of the enum strings in I18n.Type

varArgs String <repeatable>

keyTokens a vararg of all string tokens that must be constructed into a key

Version:
  • 16.3.1
Source:
Throws:

in cases where number of tokens < 2 or > 50

Type
Error
Returns:

a key generated from the passed-in tokens

Type
String
Examples

Building a key for the title text of a component on a page

var viewI8nKey = I18n.key(I18n.Type.Page, activePage.getId(), view.getId(), 'titleText');

Building a key for a display name of a field

var fieldNameKey = I18n.key(I18n.Type.Entity, entity.getId(), field.getId(), I18n.Suffix.SingularName);