Permalink
Browse files

git-svn-id: http://micolog.googlecode.com/svn/trunk@63 fd139d67-4554-…

…0410-8437-97b8145f5b4d
  • Loading branch information...
coolchyni
coolchyni committed Oct 19, 2009
1 parent 4ec07d2 commit 080397e012be131f5a25a5bf60898be47557bede
Showing with 229 additions and 3 deletions.
  1. +1 −1 base.py
  2. +2 −2 blog.py
  3. +2 −0 complie_text.bat
  4. +2 −0 gettext.bat
  5. +49 −0 tools/compile-messages.py
  6. +145 −0 tools/make-messages.py
  7. +28 −0 tools/unique-messages.py
View
@@ -288,5 +288,5 @@ def m_list_pages(self):
current= 'current_page_item'
else:
current= 'page_item'
- ret+='<li class="%s"><a href="/%s" >%s</a></li>'%( current,self.blog.baseurl+"/"+page.link, page.title)
+ ret+='<li class="%s"><a href="/%s" >%s</a></li>'%( current,page.link, page.title)
return ret
View
@@ -225,9 +225,9 @@ def get_comments_nav(self,pindex,count):
def get_comments_pagenum_link(self,pindex):
url=str(self.entry.link)
if url.find('?')>=0:
- return url+"&mp="+str(pindex)+"#comments"
+ return "/"+url+"&mp="+str(pindex)+"#comments"
else:
- return url+"?mp="+str(pindex)+"#comments"
+ return "/"+url+"?mp="+str(pindex)+"#comments"
class FeedHandler(BaseRequestHandler):
@cache(time=600)
View
@@ -0,0 +1,2 @@
+set path=D:\Program Files\Google\google_appengine\gettext;%path%
+tools\compile-messages.py -l zh_CN
View
@@ -0,0 +1,2 @@
+set path=D:\Program Files\Google\google_appengine\gettext;%path%
+tools\make-messages.py -l zh_CN
View
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import optparse
+import os
+import sys
+
+def compile_messages(locale=None):
+ basedir = None
+
+ if os.path.isdir(os.path.join('conf', 'locale')):
+ basedir = os.path.abspath(os.path.join('conf', 'locale'))
+ elif os.path.isdir('locale'):
+ basedir = os.path.abspath('locale')
+ else:
+ print "This script should be run from the Django SVN tree or your project or app tree."
+ sys.exit(1)
+
+ if locale is not None:
+ basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
+
+ for dirpath, dirnames, filenames in os.walk(basedir):
+ for f in filenames:
+ if f.endswith('.po'):
+ sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
+ pf = os.path.splitext(os.path.join(dirpath, f))[0]
+ # Store the names of the .mo and .po files in an environment
+ # variable, rather than doing a string replacement into the
+ # command, so that we can take advantage of shell quoting, to
+ # quote any malicious characters/escaping.
+ # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
+ os.environ['djangocompilemo'] = pf + '.mo'
+ os.environ['djangocompilepo'] = pf + '.po'
+ if sys.platform == 'win32': # Different shell-variable syntax
+ cmd = 'msgfmt -o "%djangocompilemo%" "%djangocompilepo%"'
+ else:
+ cmd = 'msgfmt -o "$djangocompilemo" "$djangocompilepo"'
+ os.system(cmd)
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option('-l', '--locale', dest='locale',
+ help="The locale to process. Default is to process all.")
+ options, args = parser.parse_args()
+ if len(args):
+ parser.error("This program takes no arguments")
+ compile_messages(options.locale)
+
+if __name__ == "__main__":
+ main()
View
@@ -0,0 +1,145 @@
+#!/usr/bin/env python
+
+# Need to ensure that the i18n framework is enabled
+from django.conf import settings
+settings.configure(USE_I18N = True)
+
+from django.utils.translation import templatize
+import re
+import os
+import sys
+import getopt
+
+pythonize_re = re.compile(r'\n\s*//')
+
+def make_messages():
+ localedir = None
+
+ if os.path.isdir(os.path.join('conf', 'locale')):
+ localedir = os.path.abspath(os.path.join('conf', 'locale'))
+ elif os.path.isdir('locale'):
+ localedir = os.path.abspath('locale')
+ else:
+ print "This script should be run from the django svn tree or your project or app tree."
+ print "If you did indeed run it from the svn checkout or your project or application,"
+ print "maybe you are just missing the conf/locale (in the django tree) or locale (for project"
+ print "and application) directory?"
+ print "make-messages.py doesn't create it automatically, you have to create it by hand if"
+ print "you want to enable i18n for your project or application."
+ sys.exit(1)
+
+ (opts, args) = getopt.getopt(sys.argv[1:], 'l:d:va')
+
+ lang = None
+ domain = 'django'
+ verbose = False
+ all = False
+
+ for o, v in opts:
+ if o == '-l':
+ lang = v
+ elif o == '-d':
+ domain = v
+ elif o == '-v':
+ verbose = True
+ elif o == '-a':
+ all = True
+
+ if domain not in ('django', 'djangojs'):
+ print "currently make-messages.py only supports domains 'django' and 'djangojs'"
+ sys.exit(1)
+ if (lang is None and not all) or domain is None:
+ print "usage: make-messages.py -l <language>"
+ print " or: make-messages.py -a"
+ sys.exit(1)
+
+ languages = []
+
+ if lang is not None:
+ languages.append(lang)
+ elif all:
+ languages = [el for el in os.listdir(localedir) if not el.startswith('.')]
+
+ for lang in languages:
+
+ print "processing language", lang
+ basedir = os.path.join(localedir, lang, 'LC_MESSAGES')
+ if not os.path.isdir(basedir):
+ os.makedirs(basedir)
+
+ pofile = os.path.join(basedir, '%s.po' % domain)
+ potfile = os.path.join(basedir, '%s.pot' % domain)
+
+ if os.path.exists(potfile):
+ os.unlink(potfile)
+
+ for (dirpath, dirnames, filenames) in os.walk("."):
+ for file in filenames:
+ if domain == 'djangojs' and file.endswith('.js'):
+ if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
+ src = open(os.path.join(dirpath, file), "rb").read()
+ src = pythonize_re.sub('\n#', src)
+ open(os.path.join(dirpath, '%s.py' % file), "wb").write(src)
+ thefile = '%s.py' % file
+ cmd = 'xgettext %s -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy --from-code UTF-8 -o - "%s"' % (
+ os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
+ (stdin, stdout, stderr) = os.popen3(cmd, 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running xgettext on %s" % file
+ print errors
+ sys.exit(8)
+ old = '#: '+os.path.join(dirpath, thefile)[2:]
+ new = '#: '+os.path.join(dirpath, file)[2:]
+ msgs = msgs.replace(old, new)
+ if msgs:
+ open(potfile, 'ab').write(msgs)
+ os.unlink(os.path.join(dirpath, thefile))
+ elif domain == 'django' and (file.endswith('.py') or file.endswith('.html')):
+ thefile = file
+ if file.endswith('.html'):
+ src = open(os.path.join(dirpath, file), "rb").read()
+ open(os.path.join(dirpath, '%s.py' % file), "wb").write(templatize(src))
+ thefile = '%s.py' % file
+ if verbose: sys.stdout.write('processing file %s in %s\n' % (file, dirpath))
+ cmd = 'xgettext %s -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy --from-code UTF-8 -o - "%s"' % (
+ os.path.exists(potfile) and '--omit-header' or '', domain, os.path.join(dirpath, thefile))
+ (stdin, stdout, stderr) = os.popen3(cmd, 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running xgettext on %s" % file
+ print errors
+ sys.exit(8)
+ if thefile != file:
+ old = '#: '+os.path.join(dirpath, thefile)[2:]
+ new = '#: '+os.path.join(dirpath, file)[2:]
+ msgs = msgs.replace(old, new)
+ if msgs:
+ open(potfile, 'ab').write(msgs)
+ if thefile != file:
+ os.unlink(os.path.join(dirpath, thefile))
+
+ if os.path.exists(potfile):
+ (stdin, stdout, stderr) = os.popen3('msguniq "%s"' % potfile, 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running msguniq"
+ print errors
+ sys.exit(8)
+ open(potfile, 'w').write(msgs)
+ if os.path.exists(pofile):
+ (stdin, stdout, stderr) = os.popen3('msgmerge -q "%s" "%s"' % (pofile, potfile), 'b')
+ msgs = stdout.read()
+ errors = stderr.read()
+ if errors:
+ print "errors happened while running msgmerge"
+ print errors
+ sys.exit(8)
+ open(pofile, 'wb').write(msgs)
+ os.unlink(potfile)
+
+if __name__ == "__main__":
+ make_messages()
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+def unique_messages():
+ basedir = None
+
+ if os.path.isdir(os.path.join('conf', 'locale')):
+ basedir = os.path.abspath(os.path.join('conf', 'locale'))
+ elif os.path.isdir('locale'):
+ basedir = os.path.abspath('locale')
+ else:
+ print "this script should be run from the django svn tree or your project or app tree"
+ sys.exit(1)
+
+ for (dirpath, dirnames, filenames) in os.walk(basedir):
+ for f in filenames:
+ if f.endswith('.po'):
+ sys.stderr.write('processing file %s in %s\n' % (f, dirpath))
+ pf = os.path.splitext(os.path.join(dirpath, f))[0]
+ cmd = 'msguniq "%s.po"' % pf
+ stdout = os.popen(cmd)
+ msg = stdout.read()
+ open('%s.po' % pf, 'w').write(msg)
+
+if __name__ == "__main__":
+ unique_messages()

0 comments on commit 080397e

Please sign in to comment.