Browse Source

fix swift i18n

Change-Id: I53cea28a6d7593a1b308dbcf77dddf7f40d76cb2
changes/91/39391/7
Clay Gerrard 8 years ago
committed by John Dickinson
parent
commit
ce12d66cf9
  1. 11
      swift/__init__.py
  2. 2
      swift/account/auditor.py
  3. 2
      swift/account/reaper.py
  4. 2
      swift/account/server.py
  5. 2
      swift/common/bench.py
  6. 2
      swift/common/bufferedhttp.py
  7. 2
      swift/common/db.py
  8. 2
      swift/common/db_replicator.py
  9. 2
      swift/common/internal_client.py
  10. 2
      swift/common/manager.py
  11. 2
      swift/common/memcached.py
  12. 2
      swift/common/middleware/catch_errors.py
  13. 2
      swift/common/middleware/cname_lookup.py
  14. 2
      swift/common/middleware/ratelimit.py
  15. 2
      swift/common/middleware/recon.py
  16. 2
      swift/common/utils.py
  17. 2
      swift/common/wsgi.py
  18. 2
      swift/container/auditor.py
  19. 2
      swift/container/server.py
  20. 2
      swift/container/sync.py
  21. 2
      swift/container/updater.py
  22. 2
      swift/obj/auditor.py
  23. 2
      swift/obj/diskfile.py
  24. 2
      swift/obj/expirer.py
  25. 2
      swift/obj/replicator.py
  26. 2
      swift/obj/server.py
  27. 2
      swift/obj/updater.py
  28. 2
      swift/proxy/controllers/account.py
  29. 2
      swift/proxy/controllers/base.py
  30. 2
      swift/proxy/controllers/container.py
  31. 2
      swift/proxy/controllers/obj.py
  32. 2
      swift/proxy/server.py
  33. 7
      test/__init__.py
  34. 3
      test/unit/locale/README
  35. 0
      test/unit/locale/__init__.py
  36. 2
      test/unit/locale/eo.po
  37. 1
      test/unit/locale/eo/LC_MESSAGES/swift.mo
  38. BIN
      test/unit/locale/messages.mo
  39. 41
      test/unit/locale/test_locale.py

11
swift/__init__.py

@ -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)

2
swift/account/auditor.py

@ -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

2
swift/account/reaper.py

@ -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

2
swift/account/server.py

@ -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

2
swift/common/bench.py

@ -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

2
swift/common/bufferedhttp.py

@ -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

2
swift/common/db.py

@ -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

2
swift/common/db_replicator.py

@ -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

2
swift/common/internal_client.py

@ -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

2
swift/common/manager.py

@ -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

2
swift/common/memcached.py

@ -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

2
swift/common/middleware/catch_errors.py

@ -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

2
swift/common/middleware/cname_lookup.py

@ -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

2
swift/common/middleware/ratelimit.py

@ -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

2
swift/common/middleware/recon.py

@ -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

2
swift/common/utils.py

@ -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

2
swift/common/wsgi.py

@ -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

2
swift/container/auditor.py

@ -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

2
swift/container/server.py

@ -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

2
swift/container/sync.py

@ -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

2
swift/container/updater.py

@ -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

2
swift/obj/auditor.py

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

2
swift/obj/diskfile.py

@ -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, \

2
swift/obj/expirer.py

@ -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

2
swift/obj/replicator.py

@ -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

2
swift/obj/server.py

@ -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

2
swift/obj/updater.py

@ -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

2
swift/proxy/controllers/account.py

@ -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

2
swift/proxy/controllers/base.py

@ -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

2
swift/proxy/controllers/container.py

@ -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

2
swift/proxy/controllers/obj.py

@ -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

2
swift/proxy/server.py

@ -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

7
test/__init__.py

@ -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

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

0
test/unit/locale/__init__.py

2
test/unit/locale/eo.po

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

1
test/unit/locale/eo/LC_MESSAGES/swift.mo

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

BIN
test/unit/locale/messages.mo

41
test/unit/locale/test_locale.py

@ -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…
Cancel
Save