better languages.py, thanks Vladyslav

This commit is contained in:
mdipierro
2012-09-11 13:37:16 -05:00
parent 49c82bcd65
commit 9182e7a882
22 changed files with 1474 additions and 848 deletions
+7 -31
View File
@@ -22,10 +22,8 @@ except ImportError:
have_git = False
GIT_MISSING = 'requires python-git module, but not installed or incompatible version'
from gluon.languages import (regex_language, read_possible_languages,
lang_sampling,
read_dict, write_dict, read_plural_dict,
write_plural_dict, PLURAL_RULES)
from gluon.languages import (read_possible_languages, read_dict, write_dict,
read_plural_dict, write_plural_dict)
if DEMO_MODE and request.function in ['change_password','pack','pack_plugin','upgrade_web2py','uninstall','cleanup','compile_app','remove_compiled_app','delete','delete_plugin','create_file','upload_file','update_languages','reload_routes','git_push','git_pull']:
@@ -812,7 +810,6 @@ def edit_language():
def edit_plurals():
""" Edit plurals file """
#import ipdb; ipdb.set_trace()
app = get_app()
filename = '/'.join(request.args)
plurals = read_plural_dict(apath(filename, r=request)) # plural forms dictionary
@@ -949,30 +946,11 @@ def design():
statics.sort()
# Get all languages
all_languages=dict([(lang+'.py',info[0]) for lang,info
in read_possible_languages(apath(app, r=request)).iteritems()
if info[2]!=0]) # info[2] is langfile_mtime:
# get only existed files
languages = sorted(all_languages)
plural_rules = {}
all_plurals = PLURAL_RULES
for langfile,lang in all_languages.iteritems():
lang=lang.strip()
match_language = regex_language.match(lang)
if match_language:
match_language = tuple(part
for part in match_language.groups()
if part)
plang = lang_sampling(match_language, all_plurals.keys())
if plang:
plural=all_plurals[plang]
plural_rules[langfile]=(plural[0],plang,plural[4],plural[3])
else:
plural_rules[langfile]=(0,lang,'plural_rules-%s.py'%lang,'')
plurals = listdir(apath('%s/languages/' % app, r=request),
'^plural-[\w-]+\.py$')
languages=dict([(lang,info) for lang,info
in read_possible_languages(
apath(app, r=request)).iteritems()
if info[2]!=0]) # info[2] is langfile_mtime:
# get only existed files
#Get crontab
cronfolder = apath('%s/cron' % app, r=request)
@@ -1000,8 +978,6 @@ def design():
privates=filter_plugins(privates,plugins),
statics=filter_plugins(statics,plugins),
languages=languages,
plurals=plurals,
plural_rules=plural_rules,
crontab=crontab,
plugins=plugins)
+3
View File
@@ -14,6 +14,7 @@
'%Y-%m-%d %H:%M:%S': '%Y/%m/%d %H:%M:%S',
'(requires internet access)': '(потрібно мати доступ в інтернет)',
'(something like "it-it")': '(щось схоже на "uk-ua")',
'@markmin\x01(file **gluon/contrib/plural_rules/%s.py** is not found)': '(не існує файлу **gluon/contrib/plural_rules/%s.py**)',
'@markmin\x01Searching: **%s** %%{file}': 'Знайдено: **%s** %%{файл}',
'Abort': 'Припинити',
'About': 'Про',
@@ -405,6 +406,7 @@
'ticket': 'позначка',
'Ticket': 'Позначка (Ticket)',
'Ticket ID': 'Ід.позначки (Ticket ID)',
'Ticket Missing': 'Позначка (ticket) відсутня',
'tickets': 'позначки (tickets)',
'Time in Cache (h:m:s)': 'Час в кеші (г:хв:сек)',
'to previous version.': 'до попередньої версії.',
@@ -412,6 +414,7 @@
'To emulate a breakpoint programatically, write:': 'Для встановлення точки зупинки програмним чином напишіть:',
'to use the debugger!': 'щоб активувати ладнач!',
'toggle breakpoint': '+/- точку зупинки',
'Toggle Fullscreen': 'Перемкнути на весь екран',
'Traceback': 'Стек викликів (Traceback)',
'Translation strings for the application': 'Пари рядків <оригінал>:<переклад> для вибраної мови',
'try something like': 'спробуйте щось схоже на',
+12 -17
View File
@@ -187,8 +187,9 @@ for c in controllers: controller_functions+=[c[:-3]+'/%s.html'%x for x in functi
</div>
{{if not languages:}}<p><strong>{{=T("There are no translators, only default language is supported")}}</strong></p>{{pass}}
<table>
{{for file in languages:}}
{{id="languages__"+file.replace('.','__')}}
{{for lang in sorted(languages):
file = lang+'.py'
id = "languages__"+file.replace('.','__')}}
<tr id="{{=id}}">
<td>
<span class="filetools controls">
@@ -203,24 +204,17 @@ for c in controllers: controller_functions+=[c[:-3]+'/%s.html'%x for x in functi
&nbsp;
(
{{=T("Plural-Forms:")}}
{{p=plural_rules[file]}}
{{if p[0] == 0:}}
<b>{{=T("rules are not defined")}}</b>,
<span class="controls comptools">
{{=button(URL('create_file', vars=dict(filename=p[2], location='gluon/contrib/rules/', sender=URL('design', args=app), id=id, app=app, token=session.token)), T('Create rules'))}}
</span>
{{p=languages[lang][3:7]}}
{{if p[2] == 'default':}}
<span class='error'>{{=T("rules are not defined")}}</span> {{=T.M("(file **gluon/contrib/plural_rules/%s.py** is not found)",lang[:2])}}
{{else:}}
{{if p[0] == 1:}}
{{if p[3] == 'ok':}}
{{=B(T("are not used"))}},
{{else:}}
<span class='error'>{{=B(T("rules parsed with errors"))}}</span>,
{{pass}}
{{if p[3] == 1:}}
{{=B(T("are not used"))}}
{{else:}}
{{pfile='plural-%s.py'%p[1]}}
{{if pfile in plurals:}}
{{pfile=p[0]}}
{{if p[1]!=0:}}
<span class="filetools controls">
{{=editpluralsfile('languages',pfile,dict(nplurals=p[0]))}}
{{=editpluralsfile('languages',pfile,dict(nplurals=p[3]))}}
</span>
<span class="file">
{{=peekfile('languages',pfile,dict(id=id))}}
@@ -235,6 +229,7 @@ for c in controllers: controller_functions+=[c[:-3]+'/%s.html'%x for x in functi
</tr>
{{pass}}
</table>
{{pass}}
<div class="controls formfield">{{=file_create_form('%s/languages/' % app, 'languages')}}{{=T('(something like "it-it")')}}</div>
</div>