cbi18n
Search…
Whats New With 2.0.0

Compatibility Updates

CFML Engines

Compatibility with Adobe ColdFusion 11 and Lucee 4.5 have been dropped.

Module Configuration Settings

You will need to move the i18n configuration structure in your config/ColdBox.cfc to the moduleSettings struct and rename it to cbi18n to standardize it to module settings.
1
moduleSettings = {
2
3
cbi18n = {
4
// The default resource to load and aliased as `default`
5
"defaultResourceBundle" : "includes/i18n/main",
6
// The locale to use when none defined
7
"defaultLocale" : "en_US",
8
// The default storage for the locale
9
"localeStorage" : "[email protected]",
10
// What to emit to via the resource methods if a translation is not found
11
"unknownTranslation" : "**NOT FOUND**",
12
// If true, we will log to LogBox the missing translations
13
"logUnknownTranslation" : true,
14
// A-la-carte resources to load by name
15
"resourceBundles" : {},
16
// Your own CFC instantiation path
17
"customResourceService" : ""
18
}
19
20
};
Copied!

ColdBox Module Settings

Every ColdBox module has the i18n capabilities available to them as well. They can use it to register their own resource bundles. The previous version allowed for a setting called i18n this is now called cbi18n to comply with the same global naming convention. Just update your key root in your Moduleconfig.cfc
ModuleConfig.cfc
1
cbi18n = {
2
defaultLocale = "es_SV",
3
resourceBundles = {
4
"[email protected]" = "#moduleMapping#/includes/module"
5
}
6
};
Copied!

Locale Storage Options

Major updates

JSON Resources

cbi18n v1 already had java resource bundles. v2 added support for JSON resource bundles. Both flat and nested JSON bundles are supported.

Flat

includes/i18n/jsontest_en_US.json
1
{
2
"sub.IntroMessage": "Normal JSON"
3
}
Copied!
includes/i18n/jsontest_es_SV.json
1
{
2
"sub.IntroMessage": "JSON Normal"
3
}
Copied!

Nested

includes/i18n/nested_en_US.json
1
{
2
"sub": {
3
"IntroMessage": "Nested JSON"
4
}
5
}
Copied!
includes/i18n/nested_es_SV.json
1
{
2
"sub": {
3
"IntroMessage": "JSON Incrustado"
4
}
5
}
Copied!

Locale Storage

The locale storage has now moved to leveraging a cbStorages compliant driver. This way you can leverage any of the cbStorages drivers or anything custom you would like.

Property Inheritance

In this version we introduced the concept of property inheritance. It means that key-values pairs included in less specific files are inherited by those which are higher in the inheritance tree. For example: Let's assume you are using a en_US locale. if you have key-values in a generic myResource.properties file, you can override them in a myResource_en.properties and an even more specific myResource_en_US.properties file. This opens up the possibility to define a generic language resource and define country specific translations in a more specific resource file.
The order of lookup is:
  • myBundle_en_US_somevariant.(properties|json)
  • myBundle_en_US.(properties|json)
  • myBundle_en.(properties|json)
  • myBundle.(properties|json)

New Mixin Helpers

You get some brand new helpers in this release:
1
/**
2
* Get i18n Model
3
*/
4
function i18n()
5
6
/**
7
* Get the resource service model
8
*/
9
function resourceService()
Copied!

Unknown Translation Interception

The event onUnknownTranslation is emitted via an interception when a translation is not found. You will receive the following interception data packet:
1
{
2
resource = ...,
3
locale = ... ,
4
bundle = ...
5
}
Copied!
Last modified 10mo ago