2008-08-15 17:31:51 +00:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 03:20:23 +00:00
|
|
|
## src/common/i18n.py
|
2004-05-16 23:47:14 +00:00
|
|
|
##
|
2008-08-15 03:20:23 +00:00
|
|
|
## Copyright (C) 2003-2007 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Copyright (C) 2004 Vincent Hanquez <tab AT snarc.org>
|
|
|
|
## Copyright (C) 2004-2007 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
|
2004-05-16 23:47:14 +00:00
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2004-05-16 23:47:14 +00:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 11:13:13 +00:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2004-05-16 23:47:14 +00:00
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2004-05-16 23:47:14 +00:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 03:20:23 +00:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-05-16 23:47:14 +00:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 03:20:23 +00:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 11:13:13 +00:00
|
|
|
##
|
2004-05-16 23:47:14 +00:00
|
|
|
|
2005-05-31 17:53:28 +00:00
|
|
|
import locale
|
|
|
|
import gettext
|
2005-09-05 15:32:26 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
APP = 'gajim'
|
|
|
|
if os.path.isdir('../po'):
|
|
|
|
DIR = '../po'
|
|
|
|
else:
|
|
|
|
DIR = '../../locale'
|
2004-05-16 23:47:14 +00:00
|
|
|
|
2005-12-10 16:19:58 +00:00
|
|
|
# set '' so each part of the locale that should be modified is set
|
|
|
|
# according to the environment variables
|
2004-11-15 09:43:13 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, '')
|
2006-02-21 11:12:54 +00:00
|
|
|
|
2006-02-24 21:05:05 +00:00
|
|
|
## For windows: set, if needed, a value in LANG environmental variable ##
|
2006-02-24 15:04:06 +00:00
|
|
|
if os.name == 'nt':
|
2006-02-24 21:05:05 +00:00
|
|
|
lang = os.getenv('LANG')
|
|
|
|
if lang is None:
|
2006-02-24 15:04:06 +00:00
|
|
|
default_lang = locale.getdefaultlocale()[0] # en_US, fr_FR, el_GR etc..
|
|
|
|
if default_lang:
|
|
|
|
lang = default_lang
|
2006-02-21 11:12:54 +00:00
|
|
|
|
2006-02-24 15:04:06 +00:00
|
|
|
if lang:
|
|
|
|
os.environ['LANG'] = lang
|
2006-02-21 11:12:54 +00:00
|
|
|
|
2006-06-15 06:49:04 +00:00
|
|
|
gettext.install(APP, DIR, unicode = True)
|
|
|
|
if gettext._translations:
|
|
|
|
_translation = gettext._translations.values()[0]
|
|
|
|
else:
|
|
|
|
_translation = gettext.NullTranslations()
|
2005-08-12 17:53:25 +00:00
|
|
|
|
|
|
|
def Q_(s):
|
|
|
|
# Qualified translatable strings
|
|
|
|
# Some strings are too ambiguous to be easily translated.
|
|
|
|
# so we must use as:
|
|
|
|
# s = Q_('?vcard:Unknown')
|
|
|
|
# widget.set_text(s)
|
|
|
|
# Q_() removes the ?vcard:
|
|
|
|
# but gettext while parsing the file detects ?vcard:Unknown as a whole string.
|
2005-11-12 14:20:20 +00:00
|
|
|
# translator can either put the ?vcard: part or no (easier for him or her to no)
|
2005-08-12 17:53:25 +00:00
|
|
|
# nothing fails
|
2005-08-12 18:53:29 +00:00
|
|
|
s = _(s)
|
2005-08-12 17:53:25 +00:00
|
|
|
if s[0] == '?':
|
2005-08-12 18:53:29 +00:00
|
|
|
s = s[s.find(':')+1:] # remove ?abc: part
|
2005-08-12 17:53:25 +00:00
|
|
|
return s
|
2005-08-24 11:54:47 +00:00
|
|
|
|
|
|
|
def ngettext(s_sing, s_plural, n, replace_sing = None, replace_plural = None):
|
|
|
|
'''use as:
|
|
|
|
i18n.ngettext('leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c')
|
|
|
|
|
|
|
|
in other words this is a hack to ngettext() to support %s %d etc..
|
|
|
|
'''
|
2005-08-29 12:11:14 +00:00
|
|
|
text = _translation.ungettext(s_sing, s_plural, n)
|
2005-08-24 12:23:35 +00:00
|
|
|
if n == 1 and replace_sing is not None:
|
2005-08-24 11:54:47 +00:00
|
|
|
text = text % replace_sing
|
2005-08-24 12:23:35 +00:00
|
|
|
elif n > 1 and replace_plural is not None:
|
2005-08-24 11:54:47 +00:00
|
|
|
text = text % replace_plural
|
|
|
|
return text
|
2008-07-29 19:49:31 +00:00
|
|
|
|
2008-08-15 03:20:23 +00:00
|
|
|
# vim: se ts=3:
|