python找不到文件数据_Python:使用自定义语言环境文件夹找不到域的翻译文件

1586010002-jmsa.png

I have the following structure :

/

|- main.py

|- brainz

| |- __init__.py

| |- Brainz.py

|- datas

|- locale

|- en_US

|- LC_MESSAGES

|- brainz.mo

|- brainz.po

In my __init__.py there is the following lines :

import locale

import gettext

import os

current_locale, encoding = locale.getdefaultlocale()

locale_path = '../datas/locale/' + current_locale + '/LC_MESSAGES/'

language = gettext.translation ( 'brainz', locale_path )

language.install()

But when I try to run my program I got this error :

Traceback (most recent call last):

File "main.py", line 3, in

from brainz.Brainz import *

File "/home/damien/BrainZ/brainz/__init__.py", line 11, in

language = gettext.translation ( 'brainz', locale_path )

File "/usr/lib/python2.6/gettext.py", line 484, in translation

raise IOError(ENOENT, 'No translation file found for domain', domain)

IOError: [Errno 2] No translation file found for domain: 'brainz'

I don't understand which path is expected by gettext.translation as I give a complete path to the .mo file.

Could someone explain me what I have to do to load my translation files correctly ?

Thanks,

Damien

解决方案

I think your __init__.py should be something like:

import locale

import gettext

import os

current_locale, encoding = locale.getdefaultlocale()

locale_path = 'datas/locale/'

language = gettext.translation ('brainz', locale_path, [current_locale] )

language.install()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值