fix swift i18n

Change-Id: I53cea28a6d7593a1b308dbcf77dddf7f40d76cb2
This commit is contained in:
Clay Gerrard 2013-07-30 11:44:11 -07:00 committed by John Dickinson
parent 2b91f2675f
commit ce12d66cf9
39 changed files with 93 additions and 34 deletions

View File

@ -13,9 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import gettext
import pbr.version
_version_info = pbr.version.VersionInfo('swift')
__version__ = _version_info.release_string()
__canonical_version__ = _version_info.version_string()
_localedir = os.environ.get('SWIFT_LOCALEDIR')
_t = gettext.translation('swift', localedir=_localedir, fallback=True)
def gettext_(msg):
return _t.gettext(msg)

View File

@ -15,7 +15,7 @@
import os
import time
from gettext import gettext as _
from swift import gettext_ as _
from random import random
import swift.common.db

View File

@ -15,7 +15,7 @@
import os
import random
from gettext import gettext as _
from swift import gettext_ as _
from logging import DEBUG
from math import sqrt
from time import time, ctime

View File

@ -18,7 +18,7 @@ from __future__ import with_statement
import os
import time
import traceback
from gettext import gettext as _
from swift import gettext_ as _
from eventlet import Timeout

View File

@ -22,7 +22,7 @@ import signal
import socket
import logging
from contextlib import contextmanager
from gettext import gettext as _
from swift import gettext_ as _
from optparse import Values
import eventlet

View File

@ -26,7 +26,7 @@ BufferedHTTPResponse.
make all calls through httplib.
"""
from gettext import gettext as _
from swift import gettext_ as _
from urllib import quote
import logging
import time

View File

@ -25,7 +25,7 @@ import sys
import time
import cPickle as pickle
import errno
from gettext import gettext as _
from swift import gettext_ as _
from tempfile import mkstemp
from eventlet import sleep, Timeout

View File

@ -22,7 +22,7 @@ import shutil
import uuid
import errno
import re
from gettext import gettext as _
from swift import gettext_ as _
from eventlet import GreenPool, sleep, Timeout
from eventlet.green import subprocess

View File

@ -19,7 +19,7 @@ from paste.deploy import loadapp
import struct
from sys import exc_info
import zlib
from gettext import gettext as _
from swift import gettext_ as _
from zlib import compressobj
from swift.common.utils import quote

View File

@ -22,7 +22,7 @@ import signal
import time
import subprocess
import re
from gettext import gettext as _
from swift import gettext_ as _
from swift.common.utils import search_tree, remove_file, write_file

View File

@ -49,7 +49,7 @@ import logging
import socket
import time
from bisect import bisect
from gettext import gettext as _
from swift import gettext_ as _
from hashlib import md5
from swift.common.utils import json

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from gettext import gettext as _
from swift import gettext_ as _
from eventlet import Timeout
from swift.common.swob import Request, HTTPServerError

View File

@ -28,7 +28,7 @@ rewritten and the request is passed further down the WSGI chain.
"""
import socket
from gettext import gettext as _
from swift import gettext_ as _
try:
import dns.resolver

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from gettext import gettext as _
from swift import gettext_ as _
import eventlet

View File

@ -15,7 +15,7 @@
import errno
import os
from gettext import gettext as _
from swift import gettext_ as _
from swift import __version__ as swiftver
from swift.common.swob import Request, Response

View File

@ -30,7 +30,6 @@ from hashlib import md5
from random import random, shuffle
from urllib import quote as _quote
from contextlib import contextmanager, closing
from gettext import gettext as _
import ctypes
import ctypes.util
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
@ -58,6 +57,7 @@ import codecs
utf8_decoder = codecs.getdecoder('utf-8')
utf8_encoder = codecs.getencoder('utf-8')
from swift import gettext_ as _
from swift.common.exceptions import LockTimeout, MessageTimeout
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND

View File

@ -20,7 +20,7 @@ import os
import signal
import time
import mimetools
from gettext import gettext as _
from swift import gettext_ as _
from itertools import chain
from StringIO import StringIO

View File

@ -15,7 +15,7 @@
import os
import time
from gettext import gettext as _
from swift import gettext_ as _
from random import random
from eventlet import Timeout

View File

@ -19,7 +19,7 @@ import os
import time
import traceback
from datetime import datetime
from gettext import gettext as _
from swift import gettext_ as _
from xml.etree.cElementTree import Element, SubElement, tostring
from eventlet import Timeout

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from gettext import gettext as _
from swift import gettext_ as _
from time import ctime, time
from random import random, shuffle
from struct import unpack_from

View File

@ -18,7 +18,7 @@ import os
import signal
import sys
import time
from gettext import gettext as _
from swift import gettext_ as _
from random import random, shuffle
from tempfile import mkstemp

View File

@ -15,7 +15,7 @@
import os
import time
from gettext import gettext as _
from swift import gettext_ as _
from eventlet import Timeout

View File

@ -24,7 +24,6 @@ import uuid
import hashlib
import logging
import traceback
from gettext import gettext as _
from os.path import basename, dirname, exists, getmtime, getsize, join
from tempfile import mkstemp
from contextlib import contextmanager
@ -32,6 +31,7 @@ from contextlib import contextmanager
from xattr import getxattr, setxattr
from eventlet import Timeout
from swift import gettext_ as _
from swift.common.constraints import check_mount
from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, renamer, fallocate, fsync, \

View File

@ -17,7 +17,7 @@ import urllib
from random import random
from time import time
from os.path import join
from gettext import gettext as _
from swift import gettext_ as _
import hashlib
from eventlet import sleep, Timeout

View File

@ -20,7 +20,7 @@ import shutil
import time
import itertools
import cPickle as pickle
from gettext import gettext as _
from swift import gettext_ as _
import eventlet
from eventlet import GreenPool, tpool, Timeout, sleep, hubs

View File

@ -22,7 +22,7 @@ import time
import traceback
from collections import defaultdict
from datetime import datetime
from gettext import gettext as _
from swift import gettext_ as _
from hashlib import md5
from eventlet import sleep, Timeout

View File

@ -18,7 +18,7 @@ import os
import signal
import sys
import time
from gettext import gettext as _
from swift import gettext_ as _
from random import random
from eventlet import patcher, Timeout

View File

@ -24,7 +24,7 @@
# These shenanigans are to ensure all related objects can be garbage
# collected. We've seen objects hang around forever otherwise.
from gettext import gettext as _
from swift import gettext_ as _
from urllib import unquote
from swift.account.utils import account_listing_response

View File

@ -29,7 +29,7 @@ import time
import functools
import inspect
import itertools
from gettext import gettext as _
from swift import gettext_ as _
from urllib import quote
from eventlet import spawn_n, GreenPile

View File

@ -24,7 +24,7 @@
# These shenanigans are to ensure all related objects can be garbage
# collected. We've seen objects hang around forever otherwise.
from gettext import gettext as _
from swift import gettext_ as _
from urllib import unquote
from swift.common.utils import public, csv_append

View File

@ -29,7 +29,7 @@ import mimetypes
import re
import time
from datetime import datetime
from gettext import gettext as _
from swift import gettext_ as _
from urllib import unquote, quote
from hashlib import md5

View File

@ -26,7 +26,7 @@
import mimetypes
import os
from gettext import gettext as _
from swift import gettext_ as _
from random import shuffle
from time import time

View File

@ -16,13 +16,14 @@
# See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
import sys
import os
from swift.common.utils import readconf
# make unittests pass on all locale
import swift
setattr(swift, 'gettext_', lambda x: x)
setattr(__builtin__, '_', lambda x: x)
from swift.common.utils import readconf
# Work around what seems to be a Python bug.

3
test/unit/locale/README Normal file
View File

@ -0,0 +1,3 @@
rebuild the .mo with msgfmt (included with GNU gettext)
msgfmt eo.po

View File

2
test/unit/locale/eo.po Normal file
View File

@ -0,0 +1,2 @@
msgid "test message"
msgstr "testo mesaĝon"

View File

@ -0,0 +1 @@
../../messages.mo

Binary file not shown.

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import unittest
try:
from subprocess import check_output
except ImportError:
from subprocess import Popen, PIPE, CalledProcessError
def check_output(*popenargs, **kwargs):
"""Lifted from python 2.7 stdlib."""
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be '
'overridden.')
process = Popen(stdout=PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise CalledProcessError(retcode, cmd, output=output)
return output
os.environ['LC_ALL'] = 'eo'
os.environ['SWIFT_LOCALEDIR'] = os.path.dirname(__file__)
from swift import gettext_ as _
class TestTranslations(unittest.TestCase):
def test_translations(self):
translated_message = check_output(['python', __file__])
self.assertEquals(translated_message, 'testo mesaĝon\n')
if __name__ == "__main__":
print _('test message')