2004-05-17 01:47:14 +02:00
|
|
|
## common/i18n.py
|
2005-08-03 01:03:21 +02:00
|
|
|
## -*- coding: utf-8 -*-
|
2004-05-17 01:47:14 +02:00
|
|
|
## Gajim Team:
|
2005-05-31 19:53:28 +02:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
2004-05-17 01:47:14 +02:00
|
|
|
##
|
2005-01-07 22:52:38 +01:00
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
2004-05-17 01:47:14 +02:00
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2005-05-31 19:53:28 +02:00
|
|
|
import locale
|
|
|
|
import gettext
|
2005-09-05 17:32:26 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
APP = 'gajim'
|
|
|
|
if os.path.isdir('../po'):
|
|
|
|
DIR = '../po'
|
|
|
|
else:
|
|
|
|
DIR = '../../locale'
|
2004-05-17 01:47:14 +02:00
|
|
|
|
2004-11-15 10:43:13 +01:00
|
|
|
locale.setlocale(locale.LC_ALL, '')
|
2004-05-17 01:47:14 +02:00
|
|
|
_translation = None
|
|
|
|
|
|
|
|
def init():
|
|
|
|
global _translation
|
|
|
|
try:
|
|
|
|
_translation = gettext.translation(APP, DIR)
|
|
|
|
except IOError:
|
|
|
|
_translation = gettext.NullTranslations()
|
|
|
|
|
2005-09-11 15:41:21 +02:00
|
|
|
init()
|
|
|
|
|
2004-05-17 01:47:14 +02:00
|
|
|
def _(s):
|
|
|
|
if s == '':
|
|
|
|
return s
|
2005-08-29 14:11:14 +02:00
|
|
|
return _translation.ugettext(s)
|
2005-08-12 19:53:25 +02: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.
|
|
|
|
# translator can either put the ?vcard: part or no (easier for him to no)
|
|
|
|
# nothing fails
|
2005-08-12 20:53:29 +02:00
|
|
|
s = _(s)
|
2005-08-12 19:53:25 +02:00
|
|
|
if s[0] == '?':
|
2005-08-12 20:53:29 +02:00
|
|
|
s = s[s.find(':')+1:] # remove ?abc: part
|
2005-08-12 19:53:25 +02:00
|
|
|
return s
|
2005-08-24 13:54:47 +02: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 14:11:14 +02:00
|
|
|
text = _translation.ungettext(s_sing, s_plural, n)
|
2005-08-24 14:23:35 +02:00
|
|
|
if n == 1 and replace_sing is not None:
|
2005-08-24 13:54:47 +02:00
|
|
|
text = text % replace_sing
|
2005-08-24 14:23:35 +02:00
|
|
|
elif n > 1 and replace_plural is not None:
|
2005-08-24 13:54:47 +02:00
|
|
|
text = text % replace_plural
|
|
|
|
return text
|