35

Are there any general localization/translation alternatives to gettext?

Open source or proprietary doesn't matter.

When I say alternative to gettext, I mean a library for internationalization, with a localization backend of sorts.

The reason I'm asking is because (among other things) I find the way gettext does things slightly cumbersome and static, mostly in the backend bit.

Tor Valamo
  • 33,261
  • 11
  • 73
  • 81

4 Answers4

48

First of all I think gettext is one of the best at this point.

You may take a look on Boost.Locale that may provide a better API and use gettext's dictionary model: http://cppcms.sourceforge.net/boost_locale/docs/ (not official part of Boost, still beta).


Edit:

If you don't like gettext...

These are translation technologies:

  • OASIS XLIFF
  • GNU gettext po/mo files
  • POSIX catalogs
  • Qt ts/tm files
  • Java properties,
  • Windows resources.

Now:

  • Last two total crap... Very hard to use translate and maintain, do not support plural forms.
  • Qt ts/tm -- requires usage of Qt framework. Have very similar model to gettext. Not bad solution, but limited to Qt. Not so useful in generic programs.
  • POSIX catalogs -- nobody uses them, no plural forms support. Crap.
  • OASIX XLIFF -- "standard" solution, depends on XML, even ICU requires compilation to specific ICU resources for use. Limited translation tools, I don't know any library that supports XLIFF. Plural forms not so easy to use (ICU included some support only in 4.x release).

Now what do we have?

GNU gettext, widely used, has great tools, has great plural forms support, very popular in translators community...

So decide, do you really think that gettext is not so good solution?

I don't think so. You haven't worked with other solutions at all, so try to understand how it works at first place.

cbuchart
  • 10,847
  • 9
  • 53
  • 93
Artyom
  • 31,019
  • 21
  • 127
  • 215
  • 12
    See, this is an answer I was looking for. Some actual alternatives. Doesn't matter if they're good or bad, just that I can see different ways of doing things. Apparently there aren't so many, but that's not the point. ;) – Tor Valamo Feb 03 '10 at 07:25
  • 1
    Translation these days is not done in Notepad, there are WYSIWYG tools for localization and as for development. Java or Windows resources are not in any way more difficult to translate and maintain than anything else. – Mihai Nita Feb 03 '10 at 09:07
  • 3
    Plural forms in gettext are not enough for some languages, and anyway cramming plural forms in the string is something only geeks can handle, but not normal translators (with linguistic background). Java properties can handle plurals, see MessageFormat Example: "There {0,choice,0#are no files|1#is one file|1 – Mihai Nita Feb 03 '10 at 09:09
  • AFAIK Qt ts/tm has no support for plural forms too. – bialix Feb 03 '10 at 09:21
  • 3
    @Mihai The range in pural forms is far from good enough, you usually need an simple equation. XLIFF and gettext support this (however each one in little bit different wat) and Java properties are not good enough for these urposes. Plural forms is quite compilcated issue and so far gettext provides best solution so far. – Artyom Feb 03 '10 at 15:19
  • @bialix Qt has plural forms suport, but the model is little bit different from gettext. See: http://doc.trolltech.com/qq/qq19-plurals.html – Artyom Feb 03 '10 at 15:20
  • 4
    `gettext` is very poorly maintained. The last release is back from 2010. However, if you try building it from the official code repository you will find it does not build. There no one around to support it either. – Gili Aug 14 '12 at 15:36
  • Boost locale is now part of the Boost release: http://www.boost.org/doc/libs/1_55_0/libs/locale/doc/html/messages_formatting.html – the_mandrill Jul 07 '14 at 12:44
  • 1
    @Gili `gettext` seems to be actively maintained as of Jan 4, 2015 - see http://ftp.gnu.org/gnu/gettext/, where the most recent build prior to this date is Dec 24, 2014. – Dan Nissenbaum Jan 05 '15 at 04:12
  • 1
    @DanNissenbaum I'm happy to see that. I hope the library is finally buildable using the official repository. Thanks for the head's up. – Gili Jan 06 '15 at 19:51
  • XLIFF support in ICU is not good either. If you keep XLIFF files as they suggest and use their [XLIFF To ICU ResourceBundle Format Converter](https://ssl.icu-project.org/download/xliff2icuconverter.html), whose newest version was released on 2007-Aug-20, you will find it error-prone and barely do the task. – Map X Mar 06 '15 at 05:58
11

Fluent is a new system that offers a number of adaptations that gettext lacks. Where gettext supports pluralization, fluent has a generic framework for the text variants. Where gettext uses the "untranslated" string as its translation key, fluent supports an abstract key (allowing multiple translations for something that just happens to be homonymous in the source language. Here is a more extensive comparison.

An example of fluent .ftl file, taken from firefox's preferences codebase, looks like this:

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

blocklist-window =
    .title = Block Lists
    .style = width: 55em

blocklist-description = Choose the list { -brand-short-name } uses to block online trackers. Lists provided by <a data-l10n-name="disconnect-link" title="Disconnect">Disconnect</a>.
blocklist-close-key =
    .key = w

blocklist-treehead-list =
    .label = List

blocklist-button-cancel =
    .label = Cancel
    .accesskey = C

blocklist-button-ok =
    .label = Save Changes
    .accesskey = S

# This template constructs the name of the block list in the block lists dialog.
# It combines the list name and description.
# e.g. "Standard (Recommended). This list does a pretty good job."
#
# Variables:
#   $listName {string, "Standard (Recommended)."} - List name.
#   $description {string, "This list does a pretty good job."} - Description of the list.
blocklist-item-list-template = { $listName } { $description }

blocklist-item-moz-std-listName = Level 1 block list (Recommended).
blocklist-item-moz-std-description = Allows some trackers so fewer websites break.
blocklist-item-moz-full-listName = Level 2 block list.
blocklist-item-moz-full-description = Blocks all detected trackers. Some websites or content may not load properly.
jcdyer
  • 18,616
  • 5
  • 42
  • 49
  • Abstract keys sound great but is unhelpful in practice: (a) code typically doesn't contain words but whole sentences, and these usually aren't homonymous, (b) if they are homonymous, code typically tries to avoid the ambiguity and you print "lime fruit" and "limestone", (c) if you still need/want the homonym (space constraints, or there's always enough context) you can let the software say "lime-fruit" and "lime-stone" and you give gettext a to-English file that "translates" both lime-fruit and lime-stone to lime. – toolforger Dec 31 '21 at 15:43
3

Interesting comments about gettext() and all those pro-gettext().

I'm not saying that it ain't working right in most cases, but I tried to manage one project with it and quickly felt overwhelm by the hardness of using it. Maybe there are a few user interfaces for translators today, but I did not even look. The extraction and merging of strings is just not doing it for me.

Now, I thank you Artyom for talking about XLIFF which is a much better solution for my environment since everything is XML. Oh! And there are excellent editors out there. But if you like gettext() you won't find them. 8-)

I'll suggest looking at this one for example:

https://sourceforge.net/projects/wordforge2/

Now, this may give the programmer a nightmare to make it all work, but what we want is a dream come true for the translators (and zero work by the programmer as translations pour in, because I can tell you that with gettext() I had to do all the work!)

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
  • 1
    I am aware this post is old. There is very good library Translate Toolkit (http://toolkit.translatehouse.org/). Point of gettext is: How do you define strings to translate and strings to not to. How do you extract those strings. How do you import back translated strings that are kept up-to-date after long time. It is not about editor you use to translate. You can convert po to XLIFF and back with Toolkit, using script, no handwork. – Pihhan Nov 05 '13 at 14:08
  • Yeah, my experience was around 2004 when I had to do all the work by hand to get everything to be translated. Today we have much better tools! – Alexis Wilke Nov 06 '13 at 06:34
2

There is an alternative from Zend that supports gettext *.po / *.mo files and many more formats. Many Apache servers cache the translation files because gettext is implemented as a module and the server has to be restarted to refresh the translation data.

The Zend implementation avoids this and supports many more formats:

http://framework.zend.com/manual/1.12/en/zend.translate.html

Paulo
  • 13,937
  • 1
  • 20
  • 10