fix swift i18n
Change-Id: I53cea28a6d7593a1b308dbcf77dddf7f40d76cb2
This commit is contained in:
parent
2b91f2675f
commit
ce12d66cf9
@ -13,9 +13,20 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import gettext
|
||||||
|
|
||||||
import pbr.version
|
import pbr.version
|
||||||
|
|
||||||
|
|
||||||
_version_info = pbr.version.VersionInfo('swift')
|
_version_info = pbr.version.VersionInfo('swift')
|
||||||
__version__ = _version_info.release_string()
|
__version__ = _version_info.release_string()
|
||||||
__canonical_version__ = _version_info.version_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)
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
import swift.common.db
|
import swift.common.db
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from logging import DEBUG
|
from logging import DEBUG
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
from time import time, ctime
|
from time import time, ctime
|
||||||
|
@ -18,7 +18,7 @@ from __future__ import with_statement
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from optparse import Values
|
from optparse import Values
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
@ -26,7 +26,7 @@ BufferedHTTPResponse.
|
|||||||
make all calls through httplib.
|
make all calls through httplib.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
@ -25,7 +25,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
import errno
|
import errno
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
|
|
||||||
from eventlet import sleep, Timeout
|
from eventlet import sleep, Timeout
|
||||||
|
@ -22,7 +22,7 @@ import shutil
|
|||||||
import uuid
|
import uuid
|
||||||
import errno
|
import errno
|
||||||
import re
|
import re
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
from eventlet import GreenPool, sleep, Timeout
|
from eventlet import GreenPool, sleep, Timeout
|
||||||
from eventlet.green import subprocess
|
from eventlet.green import subprocess
|
||||||
|
@ -19,7 +19,7 @@ from paste.deploy import loadapp
|
|||||||
import struct
|
import struct
|
||||||
from sys import exc_info
|
from sys import exc_info
|
||||||
import zlib
|
import zlib
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from zlib import compressobj
|
from zlib import compressobj
|
||||||
|
|
||||||
from swift.common.utils import quote
|
from swift.common.utils import quote
|
||||||
|
@ -22,7 +22,7 @@ import signal
|
|||||||
import time
|
import time
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
from swift.common.utils import search_tree, remove_file, write_file
|
from swift.common.utils import search_tree, remove_file, write_file
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ import logging
|
|||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
from swift.common.utils import json
|
from swift.common.utils import json
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
|
||||||
from swift.common.swob import Request, HTTPServerError
|
from swift.common.swob import Request, HTTPServerError
|
||||||
|
@ -28,7 +28,7 @@ rewritten and the request is passed further down the WSGI chain.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
from swift import __version__ as swiftver
|
from swift import __version__ as swiftver
|
||||||
from swift.common.swob import Request, Response
|
from swift.common.swob import Request, Response
|
||||||
|
@ -30,7 +30,6 @@ from hashlib import md5
|
|||||||
from random import random, shuffle
|
from random import random, shuffle
|
||||||
from urllib import quote as _quote
|
from urllib import quote as _quote
|
||||||
from contextlib import contextmanager, closing
|
from contextlib import contextmanager, closing
|
||||||
from gettext import gettext as _
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError, \
|
||||||
@ -58,6 +57,7 @@ import codecs
|
|||||||
utf8_decoder = codecs.getdecoder('utf-8')
|
utf8_decoder = codecs.getdecoder('utf-8')
|
||||||
utf8_encoder = codecs.getencoder('utf-8')
|
utf8_encoder = codecs.getencoder('utf-8')
|
||||||
|
|
||||||
|
from swift import gettext_ as _
|
||||||
from swift.common.exceptions import LockTimeout, MessageTimeout
|
from swift.common.exceptions import LockTimeout, MessageTimeout
|
||||||
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND
|
from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
import mimetools
|
import mimetools
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
@ -19,7 +19,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from xml.etree.cElementTree import Element, SubElement, tostring
|
from xml.etree.cElementTree import Element, SubElement, tostring
|
||||||
|
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from time import ctime, time
|
from time import ctime, time
|
||||||
from random import random, shuffle
|
from random import random, shuffle
|
||||||
from struct import unpack_from
|
from struct import unpack_from
|
||||||
|
@ -18,7 +18,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from random import random, shuffle
|
from random import random, shuffle
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import uuid
|
|||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
from gettext import gettext as _
|
|
||||||
from os.path import basename, dirname, exists, getmtime, getsize, join
|
from os.path import basename, dirname, exists, getmtime, getsize, join
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
@ -32,6 +31,7 @@ from contextlib import contextmanager
|
|||||||
from xattr import getxattr, setxattr
|
from xattr import getxattr, setxattr
|
||||||
from eventlet import Timeout
|
from eventlet import Timeout
|
||||||
|
|
||||||
|
from swift import gettext_ as _
|
||||||
from swift.common.constraints import check_mount
|
from swift.common.constraints import check_mount
|
||||||
from swift.common.utils import mkdirs, normalize_timestamp, \
|
from swift.common.utils import mkdirs, normalize_timestamp, \
|
||||||
storage_directory, hash_path, renamer, fallocate, fsync, \
|
storage_directory, hash_path, renamer, fallocate, fsync, \
|
||||||
|
@ -17,7 +17,7 @@ import urllib
|
|||||||
from random import random
|
from random import random
|
||||||
from time import time
|
from time import time
|
||||||
from os.path import join
|
from os.path import join
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from eventlet import sleep, Timeout
|
from eventlet import sleep, Timeout
|
||||||
|
@ -20,7 +20,7 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
import itertools
|
import itertools
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import GreenPool, tpool, Timeout, sleep, hubs
|
from eventlet import GreenPool, tpool, Timeout, sleep, hubs
|
||||||
|
@ -22,7 +22,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
from eventlet import sleep, Timeout
|
from eventlet import sleep, Timeout
|
||||||
|
@ -18,7 +18,7 @@ import os
|
|||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
from eventlet import patcher, Timeout
|
from eventlet import patcher, Timeout
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
# These shenanigans are to ensure all related objects can be garbage
|
# These shenanigans are to ensure all related objects can be garbage
|
||||||
# collected. We've seen objects hang around forever otherwise.
|
# collected. We've seen objects hang around forever otherwise.
|
||||||
|
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
|
|
||||||
from swift.account.utils import account_listing_response
|
from swift.account.utils import account_listing_response
|
||||||
|
@ -29,7 +29,7 @@ import time
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import itertools
|
import itertools
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from urllib import quote
|
from urllib import quote
|
||||||
|
|
||||||
from eventlet import spawn_n, GreenPile
|
from eventlet import spawn_n, GreenPile
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
# These shenanigans are to ensure all related objects can be garbage
|
# These shenanigans are to ensure all related objects can be garbage
|
||||||
# collected. We've seen objects hang around forever otherwise.
|
# collected. We've seen objects hang around forever otherwise.
|
||||||
|
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
|
|
||||||
from swift.common.utils import public, csv_append
|
from swift.common.utils import public, csv_append
|
||||||
|
@ -29,7 +29,7 @@ import mimetypes
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from urllib import unquote, quote
|
from urllib import unquote, quote
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
from gettext import gettext as _
|
from swift import gettext_ as _
|
||||||
from random import shuffle
|
from random import shuffle
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
@ -16,13 +16,14 @@
|
|||||||
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
||||||
# The code below enables nosetests to work with i18n _() blocks
|
# The code below enables nosetests to work with i18n _() blocks
|
||||||
|
|
||||||
import __builtin__
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
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.
|
# Work around what seems to be a Python bug.
|
||||||
|
3
test/unit/locale/README
Normal file
3
test/unit/locale/README
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
rebuild the .mo with msgfmt (included with GNU gettext)
|
||||||
|
|
||||||
|
msgfmt eo.po
|
0
test/unit/locale/__init__.py
Normal file
0
test/unit/locale/__init__.py
Normal file
2
test/unit/locale/eo.po
Normal file
2
test/unit/locale/eo.po
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
msgid "test message"
|
||||||
|
msgstr "testo mesaĝon"
|
1
test/unit/locale/eo/LC_MESSAGES/swift.mo
Symbolic link
1
test/unit/locale/eo/LC_MESSAGES/swift.mo
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../messages.mo
|
BIN
test/unit/locale/messages.mo
Normal file
BIN
test/unit/locale/messages.mo
Normal file
Binary file not shown.
41
test/unit/locale/test_locale.py
Normal file
41
test/unit/locale/test_locale.py
Normal 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')
|
Loading…
Reference in New Issue
Block a user