Questions tagged [gettext]

Gettext is an internationalization and localization (i18n) library which is commonly used for writing multilingual programs. Its most popular implementation is that of the GNU project.

Gettext is an internationalization and localization (i18n) library which is commonly used for writing multilingual programs. Its most popular implementation is that of the GNU project.

I18n with gettext works by marking up translatable strings in the source code, usually by wrapping them with a function call. The xgettext tool extracts these strings and creates a text file listing them. This file is called the template and its name usually ends in ".pot".

The msginit tool creates a new text file mapping the extracted strings to their translation in a given locale, having the ".po" extension. Finally the msgfmt tool creates an optimized representation of the translation mappings that is then used at runtime. For most programs this is a binary file ending in ".mo", but it is also possible to create other formats, for example a java ResourceBundle.

There are specialized editors for editing the ".mo" files, which can remember already translated strings and contain databases of repeatedly used words.

1756 questions
22
votes
5 answers

How to add a new string to a *.po file w/ a PO editor

I MANUALLY created a file: test.po with the contents: msgid "greeting" msgstr "Hello World" Now I can edit the translation (hello world) in editors like "poedit" and "GTranslated" (I'm using Ubuntu). I can even add comments to that translation.…
pirhac
  • 887
  • 2
  • 8
  • 16
22
votes
3 answers

PHP Localization Best Practices? gettext?

We are in the process of making our website international, allowing multiple languages. I've looked into php's "gettext" however, if I understand it right, I see a big flaw: If my webpage has let's say "Hello World" as a static text. I can put the…
Nathan H
  • 48,033
  • 60
  • 165
  • 247
22
votes
6 answers

How to install GNU gettext on windows 7?

I need to install version 0.15 or higher of GNU's gettext so that I can use some i18n feateres with django. I've downloaded : http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.3.1.tar.gz from https://www.gnu.org/software/gettext/ However I have no…
Marijus
  • 4,195
  • 15
  • 52
  • 87
21
votes
1 answer

Alowing 'fuzzy' translations in django pages?

I've done some research and found that django translations don't show up when a string is marked as "fuzzy". However, I haven't been able to find any documentation on whether I can override this behaviour. Is there a Django setting that can be used…
user764357
20
votes
2 answers

.po files and gettext VS JSON and custom i18n library?

I need to develop or find some sort of lightweight gettext-like library in JavaScript for browser-side translations. Preferably the same library could be used by node.js if I'd like to translate server-side instead. 1) But, what are really the pros…
dani
  • 4,880
  • 8
  • 55
  • 95
20
votes
5 answers

Django switching, for a block of code, switch the language so translations are done in one language

I have a django project that uses a worker process that sends emails to users. The worker processes listens to a rabbitmq server and gets all the details about the email to send, the template variables, the email address to send to etc. The email…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
20
votes
2 answers

Can't get gettext (php) on Ubuntu working

The following example works on Mac OS X with Apache, i.e. I get the translated string echoed back. But on Ubuntu with lighttpd I get the original text 'Inactive account'. I've tried all sorts of combinations of environment varialbes without any…
pthulin
  • 4,001
  • 3
  • 21
  • 23
20
votes
7 answers

How to debug gettext not working in PHP?

i am trying to use the php gettext extension in php 5.5 (on win2008 server, using IIS7). I am doing this:
glutz
  • 1,889
  • 7
  • 29
  • 44
19
votes
3 answers

Android Edittext- Clearing Spans

I am trying to get an EditText to clear its spans by calling EditText.getText().clearSpans(). However, if I call this method, the EditText starts to behave strangely, with line feeds appearing as boxes and any spans I then set being in completely…
Henry Thompson
  • 2,441
  • 3
  • 23
  • 31
19
votes
1 answer

How to avoid flake8's "F821 undefined name '_'" when _ has been installed by gettext?

Problem overview: In my project's main script, gettext installs the function _() that is used in other modules for translations (like in print(_('Something to translate'))). As stated by the doc: the _() function [is] installed in Python’s builtins…
zezollo
  • 4,606
  • 5
  • 28
  • 59
19
votes
4 answers

Online editing gettext files?

Online editing gettext files, is it possible? I use gettext for all my PHP projects, but sides with a minor problem, want to mine user may translate my language from as Danish to Norwegian, but in this case it enste I know is that I need to export…
ParisNakitaKejser
  • 12,112
  • 9
  • 46
  • 66
19
votes
4 answers

How to generate a .po file?

On Windows using WAMPserver (Apache, MySQL, PHP) I have the following: //test.php if (!defined('LC_MESSAGES')) define('LC_MESSAGES', 6); $lang = "sv"; putenv("LANG=$lang"); setlocale(LC_ALL, $lang); $domain = "messages"; bindtextdomain($domain,…
tobefound
  • 1,091
  • 2
  • 9
  • 15
19
votes
6 answers

Where's the 3-way Git merge driver for .PO (gettext) files?

I already have following [attr]POFILE merge=merge-po-files locale/*.po POFILE in the .gitattributes and I'd like to get merging of branches to work correctly when the same localization file (e.g. locale/en.po) has been modified in paraller…
Mikko Rantalainen
  • 14,132
  • 10
  • 74
  • 112
18
votes
1 answer

How can I apply gettext translations to string literals in case statements?

I need to add gettext translation to all the string literals in our code, but it doesn't work with literals in case statements. This failed attempt gives SyntaxError: Expected ':': from gettext import gettext as _ direction = input(_('Enter a…
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485
18
votes
1 answer

How to generate translation file for a custom Drupal 7 module?

I'm using CentOS 5.5 Linux (without X), PHP 5.3 and Drupal 7.0. The core language of my site is Russian (not English)! I've created a game.info and the following game.module which generates 3 blocks for the front page: function game_block_info() { …
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416