Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding rudimentary RTL support

*   Added `{{ LANGUAGE_DIRECTION }}` tag that is replaced with either
    `ltr` or `rtl` according to a whitelist culled [from Wikimedia][1].
    Thanks to [Tom Bigelajzen][2] for the push in the right direction.

*   Converted `isGettextAvailable` to a static method.

[1]: http://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
[2]: http://tombigel.com/
  • Loading branch information...
commit 0e99132381c3630ae444f8eb7a9b4fe86592765f 1 parent 81e7a36
@mikewest authored
Showing with 25 additions and 3 deletions.
  1. +25 −3 static_gettext.py
View
28 static_gettext.py
@@ -53,7 +53,8 @@ def __init__( self, domain, inputbase, localebase, outputbase, languages, extens
else:
self.extensions = extensions
- def gettextIsAvailable( self ):
+ @staticmethod
+ def gettextIsAvailable():
requirements = { 'xgettext': False, 'msguniq': False , 'msgmerge': False }
for path in os.environ["PATH"].split( os.pathsep ):
for name in requirements:
@@ -67,6 +68,24 @@ def gettextIsAvailable( self ):
return True
+ @staticmethod
+ def getLocaleDirection( locale ):
+ # Directionality culled from http://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code
+ langToDir = {
+ "ar": "rtl", # Arabic
+ "arc": "rtl", # Aramaic
+ "dv": "rtl", # Divehi
+ "fa": "rtl", # Persian
+ "ha": "rtl", # Hausa
+ "he": "rtl", # Hebrew
+ "ks": "rtl", # Kashmiri
+ "ku": "rtl", # Kurdish
+ "ps": "rtl", # Pashto
+ "ur": "rtl", # Urdu
+ "yi": "rtl" # Yiddish
+ }
+ return langToDir.get( locale, "ltr" )
+
def localedir( self, locale ):
return os.path.join( self.localebase, locale, 'LC_MESSAGES' )
@@ -137,9 +156,12 @@ def puttextize( self, file, locale ):
if extension in self.extensions:
src = self.templatize( file=file, type=Localizer.PUTTEXT, locale=locale, l10n=l10n )
- # Replace `{{ LANGUAGE_CODE }}` with a BCP47 language tag
+ # Replace `{{ LANGUAGE_CODE }}` with a BCP47 language tag:
src = src.replace( r'{{ LANGUAGE_CODE }}', locale.lower().replace( '_', '-' ) )
+ # Replace `{{ LANGUAGE_DIRECTION }}` with `ltr` or `rtl`, depending:
+ src = src.replace( r'{{ LANGUAGE_DIRECTION }}', Localizer.getLocaleDirection( locale ) )
+
with open( outfile, 'wb' ) as f:
f.write( src.encode( 'utf-8' ) )
else:
@@ -241,7 +263,7 @@ def main():
inputbase=options.inputbase, localebase=options.localebase,
languages=options.languages, extensions=options.extensions )
- if not l10n.gettextIsAvailable():
+ if not Localizer.gettextIsAvailable():
parser.error( "Couldn't find `gettext` in your PATH. Can you please verify that it's correctly installed? (See http://www.gnu.org/software/gettext/#downloading )" );
else:
if options.build:
Please sign in to comment.
Something went wrong with that request. Please try again.