Showing posts with label gettext. Show all posts
Showing posts with label gettext. Show all posts

Sunday, August 20, 2017

how to translate using gettext on xampp server on OS X El Capitan version 10.11.6

Leave a Comment

I am working on a website that is using gettext for translation. The website is translating properly on servers of other machines but not on mine (OS X El Capitan version 10.11.6). I have follow the following tutorial to install gettext on mac:

link to the tutorial I followed

After the installation, gettext is not still working. Can someone help me here??

1 Answers

Answers 1

I followed pretty much the same instructions on Sierra (maybe you have messed up at some point?):

  1. Install the latest version of Xcode Command Line Tools. (by entering the following command in the terminal: xcode-select –install)
  2. Download the latest version of gettext and extract it to /Source or whatever you like.
  3. In the /Source director enter in the terminal: ./Configure, make, and sudo make install
  4. Download the PHP version that matches your system and extract it
  5. Change in the PHP source to the directory ext/gettext and enter the following commands: phpize, ./Configure, make, and sudo make install (each on a separate line). At this point you might get an SIP error, because the install has no access to /usr/libexec/php/extensions. However, the extension was created in the PHP source folder ext/gettext/modules
  6. Create a local extension folder: mkdir -p /usr/local/macoperator/lib/php/extensions and copy the newly created gettext.so extension to this folder
  7. Reference the local extension folder in your /etc/php.ini. Just add the following line at the end:

    extension_dir = "/usr/local/macoperator/lib/php/extensions" [gettext] extension=gettext.so

  8. Finally, make sure apache is restarted, by issuing:

    server-apachectl graceful

  9. Checking `phpinfo(), do you see:

    GetText Support enabled

Alternatively, you could try install PHP via Homebrew.

Read More

Wednesday, January 4, 2017

Create a Lua like JavaScript I18n internationalization

Leave a Comment

In our Freifunk project gluon, we use i18n GNU gettext internationalisation in our Lua code (for example for the package gluon-config-mode-hostname) we create separate files in a subfolder i18n. I want to use this .po files to add them in our status-page javascript code: https://github.com/rubo77/gluon/tree/status-i18n/package/gluon-status-page/i18n

Those contain the translations created by the msginit program.

How can I use the same i18n files for the javascript based status-page (without jQuery) to translate those strings?

1 Answers

Answers 1

Here's a dirty but verbose way of accomplishing it. Is this what you're looking for?

let url = "https://raw.githubusercontent.com/freifunk-gluon/gluon/master/package/gluon-config-mode-hostname/i18n/de.po"    fetch(url)    .then((res) => {      return res.body.getReader();    })    .then((reader) => {      return reader.read();    })    .then((stream) => {      let decoder = new TextDecoder();      let body = decoder.decode(stream.value || new Uint8Array);      return body    })    .then((body) => {      let text = body.replace(/\\n/g, '');      let lines = text.split('\n');        console.log(text)          let arr = []      let obj = {}          for (let i = 0; i < lines.length; i++) {          // key:value pairs        if (lines[i].indexOf(':') !== -1) {          let line = lines[i].replace(/"/g, '');          let pair = line.split(':');          if (pair.length) {            obj[pair[0]] = pair[1].trim();          }        }            // msgid        if (lines[i].indexOf('msgid') !== -1) {          let msgobj = {};          let msgid = lines[i].split(' "')[1].replace(/\"/g, '');          msgobj.msgid = msgid;            // msgstr          if (lines[i+1].indexOf('msgstr') !== -1) {            let msgstr = lines[i+1].split(' "')[1].replace(/\"/g, '');            msgobj.msgstr = msgstr;          }            arr.push(msgobj);                }        }          arr.push(obj)          document.getElementById('output-source')      .innerHTML = body        document.getElementById('output-js')      .innerHTML = JSON.stringify(arr, null, 2);  });
.output {    background-color: #fafafa;    border: 1px solid #e1e1e1;  }
<pre id="output-source" class="output"></pre>  <pre id="output-js" class="output"></pre>

NB: Above example likely only works in Chrome. Here's a JSBin that should work in FF.

Read More

Wednesday, April 27, 2016

Alowing 'fuzzy' translations in django pages?

Leave a Comment

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 to allow Django (or gettext) to use "fuzzy translations"?


I know a lot of the automated translations won't be perfect, but this is for demonstration, development and testing for an open-source product.

I'd rather have users be able to develop in their own language with "approximate" translations then use that as an incentive to check them off as they go.

1 Answers

Answers 1

It would be unfortunate to show these translations as some of them are most certainly wrong. You are supposed to remove the fuzzy tag when you update the translations and revise the guessed translations that are marked as fuzzy.

However, you may run a tool to quickly delete the fuzzy markers from a .po file: Removing all fuzzy entries of a PO file


UPDATE

Here is a great overview of the GNU gettext work-flow: https://www.gnu.org/software/gettext/manual/gettext.html#Overview

It is msgfmt that strips the fuzzy translations. It has an option --use-fuzzy that includes the fuzzy translations.

msgfmt is wrapped by compilemessages django admin command, which since version 1.8 has the --use-fuzzy option too (https://docs.djangoproject.com/en/1.9/ref/django-admin/#compilemessages)

Read More