Git Product home page Git Product logo

cfwheels-localerb's Introduction

LocaleRB - CFWheels

LocaleRB provides the easiest to use locale class for CFWheels. Using the locale cfcs created by Paul Hastings and Java's built in ResourceBundles, you can easily make your site translate across different locales.

Installation

After installing the plugin, there is one configuration option available, which can be set in your settings.cfm inside the config folder:

set(defaultLocale="es_ES");

This sets the default locale that will be used in the application when no other locale is set for the user's session.

LocaleRB uses java's resource bundle format for creating the different translations. These bundles are stored in a locale folder off of the root of the CFWheels application. You will need to create this.

###.properties files

LocaleRB uses .properties files for storing the translations. The naming of these files is important. For example email_en_US.properties would create an email bundle that contains the en_US translations. Likewise, you could make one for the spanish version by creating email_es_ES.properties. There is a default bundle that can be made called global which can simplify your code (see Usage) if you don't want to make several different bundles (i.e. global_en_US.properties).

For information on how to enter the translations in the file see Wikipedia. The .properties files contain simple key value pairs:

Day=Day
Month=Month
Year=Year

Day=Dia
Month=Mes
Year=Ano

Inside the locale folder, simply create as many .properties files as needed for you application with the translations. LocaleRB will recursively scan this folder for all .properties files, so you can store bundles together in a folder if wanted, etc. With that, you should be ready to start using the methods.

Usage

LocaleRB comes with several handy methods for retrieving translations and localizing strings.

$(key,[locale])

This is the main function. Returns the value associated with the key passed. Optionally pass the locale wanted. Defaults to either the set locale for the user, or the default locale for the site.

####Examples

Retrieve the key 'hello' in the email bundle:

$('email.hello') = "Hello"
$('email.hello','es_ES') = "Hola"

Retrieve the key 'goodbye' in the global bundle:

$('goodbye') = "Goodbye"
$('global.goodbye','es_ES') = "Adios"

If you remember, the global bundle is the default, so you don't need to pass the bundle necessarily in these cases - it defaults to global.

localeMessageFormat(pattern,args,[locale])

Returns string with dynamic values substituted. See http://download.oracle.com/javase/1.4.2/docs/api/java/text/MessageFormat.html for more information. Locale is optional.

setCurrentLocale(locale)

Sets the current locale for the user. Stored in the session scope. Example:

setCurrentLocale('fr_FR')

getCurrentLocale()

Returns the current locale being used for the user. Pulled from either the default locale or session scope.

reinitializeLocaleRB()

Re-initializes the locale struct stored in the application scope. Use this to re-read the .properties files.

Building From Source

rake build

History

Version 0.1 - Initial Release

Version 0.2 - Fixed output issue

Version 0.3 - Locale cache now reloads when the application reloads - much easier during development

Version 0.3.1 - Added locking for certain variables

cfwheels-localerb's People

Contributors

dbeard avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

indynz devalnor

cfwheels-localerb's Issues

Intermittent error

Hey Danny,

I've been using your plug-in to implement English and Spanish on my CFWheels 1.1.8 / Railo 3.3 website and it's been really terrific, thanks!

The only issue that's troubling me is one where an error is experienced by some users (but not all), that a key or bundle does not exist.

I am unable to replicate this error which makes it even more frustrating, but I do receive CFWheels generated error reports which proves that users do, in fact, encounter this issue.

The strange thing is that I modified the plug-in's "throw" error to tell me the specific key/bundle that supposedly does not exist, but when an error is thrown, the key in question does exist! Even in the CFWheels generated email, the bundle structs are listed and show that it exists.

Any ideas for where I can look to resolve this?

Thanks so much!
Maya

Add debug mode

Add a debug mode that lets you wrap the localized string in some sort of a string so that it's easier to pick out portions of the site that are/are not localized

seems not work with 1.1.5

Hi, excuse my poor english.
The plugin seems not working since I use the 1.1.5 version of cfwheels.
I have this message after reinitialize localRB.

throw("Key or bundle does not exist in resource bundles.")

It's dosen't work with global file or another....
I try version 0.1 on cfwheels site and the last 0.3.1...

Thanks in advance...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.