GithubHelp home page GithubHelp logo

i18n's Introduction

i18n

Internationalization in Linux with libintl & gettext.

  • POT: Portable Object Template
  • PO: Portable Object
  • MO: Machine Object

Create template

Create a POT for a file

xgettext -s -o main.pot main.cpp -k_ 

With the keywords (prefixes) _ _n and _d

xgettext -s -o main.pot main.cpp -k_ -k_n -k_d --package-name=main --package-version=1

Create a translations file

Create a PO from the POT in es_CO

msginit -l es_CO.UTF-8 -o main.po -i main.pot

If it was not auto translated fill the translations in msgstr.
Set the charset to UTF-8

Create a binary file

Create a MO from the PO

msgfmt -c -v -o main.mo main.po 

Review

Check if the program is loading the .MO correctly

strace -e trace=openat ./libintl_gettext

Use msgunfmt for reverse-compiling .mo files

The code

mkdir build && cd build
cmake -DCMAKE_MODULE_PATH=$PWD -DCMAKE_BUILD_TYPE=Debug ..
cmake --build .

CMake-configure creates de POT template in ./build/locale/es/LC_MESSAGES
Then, create the .PO file with msginit.
Fill the translations, including the plural forms.
Then, create the .MO file with msgfmt.

Then run

./build/libintl_gettext 

The messages should be shown in Spanish, one of them with the plural form.

Poedit

The application Poedit is used to create and modify PO and MO files from POT files. Having a POT you can generate a PO and fill the translations. It is particularly useful when having an already translated PO file, and updating the POT, then you can update the PO from the POT using Poedit.


See:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.