Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Adding rudimentary RTL support
Browse files Browse the repository at this point in the history
*   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
mikewest committed Oct 28, 2010
1 parent 81e7a36 commit 0e99132
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions static_gettext.py
Expand Up @@ -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:
Expand All @@ -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' )

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e99132

Please sign in to comment.