Skip to content

dmitriid/rberl

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
OVERVIEW
========

Java uses Resource Bundles for i18n stuff.

Here's a typical bundle:

    lang.properties
    ---------------

    key1 = value1
    key2 = value2
    multiline = Line 1\
                Line 2\
                Line 3


Non-ASCII symbols are encoded as Unicode Entities:

    russian_letter_ya = \u044F

See more info on Jva properties files at
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)

rberl will try to bring Resourse Bundles' functionality (most of it anyway) to Erlang

GETTING STARTED
===============

ALSO SEE EDOCS IN THE DOCS DIRECTORY!

The library comes in two flavors: a module to process .properties files and a gen_server

You can use the module to handle translations yourself or use the gen_server for a
(questionably) easier handling.

TO USE THE MODULE
-----------------

1. Compile rberl.erl from src folder
2. run

     > rberl:rberl:process_file("./../examples/lang.properties").

   to get a proplist containing all key-value pairs from the specified file

TO USE THE GEN_SERVER
---------------------

1. Compile both rberl.erl and rberl_server from src folder
2. run

     > rberl_server:start()

   to start the server

3. run

     > rberl_server:load("./../examples/", "lang").

   to load strings from all *.properties files that start with "lang" from the
   specified directory

4. run

     > rberl_server:get("multiline", "ru").

   to get the value associated with key "multiline" for locale "ru"

5. run

     > rberl_server:reload().

   to reload all files

MISC
----

- When calling load, make sure that the dir ends in a trailing slash (to be fixed)
- When retrieving keys, make sure that "complex" locales use underscores. I.e.
  use ru_RU and ru_RU_UNIX instead of ru-ru and ru-ru_UNIX


CURRENT FEATURES
===============

1. Parses .properties files into key-value pairs
2. Both keys and values are strings (lists)
3. Parses multiline values
4. Parses unicode values in the form \uxxxx
5. Handles all of the weirdness described here:
   http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)


TESTS
=====
The included tests was created using the ABNF generator from
http://www.quut.com/abnfgen/

See the ABNF for Java properties file in priv/properties.abnf

The ABNF does no define a correct properties file, however. Here's a properties file that conforms to the abnf-file:

------- start sample properties file ----------

key = value
key2 : value2
key3 value3
key4 = a multiline\
       value
an_invaild_line

-------- end sample properties file ------------

The purpose is to create a parser that will process such a file and simply 
skip over invalid lines as if they were comments

Test results have been coded by hand, so there are bound to be errors

REQUIREMENTS
============

Should run on R12B or later

Specific modules:
unicode, http://erlang.org/doc/man/unicode.html

About

Read and load Java Resource Bundles in Erlang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages