• Stars
    star
    11
  • Rank 1,640,314 (Top 34 %)
  • Language
    Julia
  • License
    Other
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

i18n for Julia

Gettext.jl

Build Status Coverage Status

An interface to the gettext internationalization/translation interface.

Installation

Within Julia, run Pkg.update() and then Pkg.add("Gettext")

Usage

A simple string can be translated as follows:

using Gettext

bindtextdomain("sample", "po/")
textdomain("sample")

println(_"Hello, world!")

In fact, such a sample program can be run from the toplevel directory of this repository as follows:

$ LANGUAGE=fr julia helloworld.jl
Bonjour le mondeย !

String interpolation

For string interpolation, you will need to use a runtime method (e.g. Formatting.jl) rather than Julia's built-in compile-time interpolation syntax. If using Formatting.jl, it probably makes sense to use the "Python" formatting style, as it allows the translations to have different argument orders than the original strings. For example,

using Gettext
using Formatting

bindtextdomain("sample", "po/")
textdomain("sample")

daystr(n) = format(ngettext("{1} day", "{1} days", n), n)

println(daystr(1))
println(daystr(3))

When run, this gives

$ LANGUAGE=fr julia daystr.jl
1 jour
3 jours

Status

Currently this library relies on Python's built-in gettext.py implementation via PyCall. In the future, it may make sense to port this code into a Julia-native version (see issue #1).