cbi18n
Search…
Overview
The cbi18n module was built to provide localization and internationalization features to any ColdBox application. It will not only allow you to represent resources in multiple languages, but will also track the user's locale for you. It has a plethora of utilities for localizing strings, dates, currencies and much more.
There are two main models that are registered for you with the following WireBox Id's:
  • [email protected] : Service that tracks user's locale, changing of locales, and a plethora of localized functions. It also bootstraps the resource bundles used in the application.
  • [email protected] In charge of retrieving language keys from locale specific resource bundles, whether they are Java property files or JSON bundles.
They can either be injected or called via our mixin helpers:
1
// Mixins
2
i18n()
3
resourceService()
4
5
// Injection
6
property name="i18n" inject="[email protected]";
7
property name="resourceService" inject="[email protected]"
Copied!
Once you have access to those objects you can leverage their methods to your ❤️'s content.
1
Your locale is #getFwLocale()#!
2
3
// localized button
4
#html.submitButton( $r( 'btn.submit' ) )#
5
6
// Localized string with replacements via arrays
7
#html.h2( $r(resource="txt.hello", values=[ "Luis", "Majano" ] ) )#
8
9
// txt.hello resource
10
txt.hello="Hello Mr {1} {2}! I hope you have an awesome day Mr. {2}!"
11
12
// Localized string with replacements via structs
13
#html.h2( $r( resource="txt.hello", values={ name="Luis", age="35" } ) )#
14
15
// txt.hello resource
16
txt.hello="Hello Mr {name}! You are {age} years old today!"
17
18
// Localized string from a bundle, notice the @cbcore alias
19
20
21
// function change a user's locale
22
function changeLocale(event,rc,prc){
23
setFwlocale( rc.locale );
24
relocate( 'home' );
25
}
Copied!
Please see the api docs for the latest methods available to you: https://apidocs.ortussolutions.com/coldbox-modules/cbi18n/2.1.0/index.html
Last modified 10mo ago
Copy link
Edit on GitHub