Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:10:07+00:00 2026-05-31T20:10:07+00:00

I’m building a Python application that utilizes a bunch of translated strings. The directory

  • 0

I’m building a Python application that utilizes a bunch of translated strings. The directory structure housing said strings looks like this:

/locales
    default.pot # reference English strings live here
    /es_ES
        /LC_MESSAGES
            default.po #Spanish strings
    /de_DE
        /LC_MESSAGES
            default.po #German strings

These default.po files were generated by a PHP application, but as far as I know, they conform to the general standard needed to work with gettext implementations.

When I attempt to utilize these strings in Python using gettext, the following goes down (this example was run from within the locales directory:

>>> import os; os.listdir('.')
['.svn', 'de_DE', 'default.pot', 'eng', 'es_ES', 'fr_FR', 'ja_JP', 'ko_KR', 'pl_PL', 'pt_BR', 'ru_RU']
>>> import os.path
>>> os.path.exists('./es_ES/LC_MESSAGES/default.po')
True
>>> import gettext
>>> ldir = 'es_ES/LC_MESSAGES/'
>>> t = gettext.translation('default',ldir)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 469, in translation
IOError: [Errno 2] No translation file found for domain: 'default'
>>>

I’m not sure what I’m doing wrong here (beyond inexperience with this library and the notion of ‘domain’ in its context).

Am I making a simple mistake? Or do I have a fundamental flaw in my understanding of how this crap works?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:10:09+00:00Added an answer on May 31, 2026 at 8:10 pm

    I’m very rusty on this, but based on past experience and http://docs.python.org/library/gettext, I can see two main things missing here:

    1. ldir should be set to the base directory containing locale data (/usr/share/locale is the classic system location). gettext will search for ldir/lang_COUNTRY/catalog.mo
    2. The .po files can’t be read on their own, you need to convert them to .mo binary files. Typically you’d use msgfmt to do this (“brew install gettext” on the mac is the easiest way to get this).

    A quick example:

    $ find /tmp/locales -type f
    /tmp/locales/de_DE/LC_MESSAGES/default.mo
    /tmp/locales/de_DE/LC_MESSAGES/default.po
    /tmp/locales/default.pot
    /tmp/locales/en_IE/LC_MESSAGES/default.mo
    /tmp/locales/en_IE/LC_MESSAGES/default.po
    
    $ ~/Library/homebrew/Cellar/gettext/0.18.1.1/bin/msgfmt \
    -o locales/en_IE/LC_MESSAGES/default.mo \
    locales/en_IE/LC_MESSAGES/default.po
    
    $ cat /tmp/app.py 
    import gettext
    t = gettext.translation('default', "/tmp/locales")
    _ = t.ugettext
    
    print _("Hello World")
    
    $ locale
    LANG="en_IE.UTF-8"
    LC_COLLATE="en_IE.UTF-8"
    LC_CTYPE="en_IE.UTF-8"
    LC_MESSAGES="en_IE.UTF-8"
    LC_MONETARY="en_IE.UTF-8"
    LC_NUMERIC="en_IE.UTF-8"
    LC_TIME="en_IE.UTF-8"
    LC_ALL=
    
    $ python app.py 
    How's the craic?
    
    $ LC_MESSAGES=de_DE python app.py
    Guten Tag
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.