i18n başlangıcı.

bu dosyaların başındaki import gettext ile başlayan üç satırlık kısım
modüllere ekleniyor, stringler ise _( ... ) içine alınıyor. pygettext.py
adlı programla .pot dosyası oluşturulup çevrilebiliyor.

translation instance'ını globale almayı kalkmayın, zaten tüm çeviriler
gettext modülü tarafından cache'leniyor.
This commit is contained in:
Gürer Özen
2005-08-17 11:35:47 +00:00
parent c853ed01a8
commit ce9772007b
3 changed files with 62 additions and 61 deletions
+8 -4
View File
@@ -12,6 +12,10 @@
import sys import sys
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
from pisi.cli.pisicli import PisiCLI from pisi.cli.pisicli import PisiCLI
from pisi.ui import ui from pisi.ui import ui
@@ -22,20 +26,20 @@ def handle_exception(exception, value, tb):
from pisi.ui import ui from pisi.ui import ui
if exception == exceptions.KeyboardInterrupt: if exception == exceptions.KeyboardInterrupt:
ui.error("\nKeyboardInterrupt: Exiting...\n") ui.error(_("\nKeyboardInterrupt: Exiting...\n"))
sys.exit(1) sys.exit(1)
elif exception == XmlError: elif exception == XmlError:
ui.error(str(value)) ui.error(str(value))
sys.exit(1) sys.exit(1)
ui.error(""" ui.error(_("""
Internal PISI Error: Internal PISI Error:
Please file a bug report! (http://bugs.uludag.org.tr) Please file a bug report! (http://bugs.uludag.org.tr)
""") """))
ui.error("%s\n" %value) ui.error("%s\n" %value)
ui.info("Traceback:\n") ui.info(_("Traceback:\n"))
traceback.print_tb(tb) traceback.print_tb(tb)
sys.exit(1) sys.exit(1)
+25 -21
View File
@@ -17,6 +17,10 @@
import os import os
import sys import sys
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
import pisi import pisi
import pisi.util as util import pisi.util as util
from pisi.ui import ui from pisi.ui import ui
@@ -70,7 +74,7 @@ def check_path_collision(package, pkgList):
# path.pathname: /usr/share/doc # path.pathname: /usr/share/doc
if util.subpath(pinfo.pathname, path.pathname): if util.subpath(pinfo.pathname, path.pathname):
collisions.append(path.pathname) collisions.append(path.pathname)
ui.error('Path %s belongs in multiple packages\n' % ui.error(_('Path %s belongs in multiple packages\n') %
path.pathname) path.pathname)
return collisions return collisions
@@ -102,8 +106,8 @@ class PisiBuild:
def build(self): def build(self):
"""Build the package in one shot.""" """Build the package in one shot."""
ui.info("Building PISI source package: %s\n" % self.spec.source.name) ui.info(_("Building PISI source package: %s\n") % self.spec.source.name)
util.xterm_title("Building PISI source package: %s\n" % self.spec.source.name) util.xterm_title(_("Building PISI source package: %s\n") % self.spec.source.name)
self.compile_action_script() self.compile_action_script()
@@ -136,30 +140,30 @@ class PisiBuild:
os.environ.update(evn) os.environ.update(evn)
def fetch_source_archive(self): def fetch_source_archive(self):
ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri) ui.info(_("Fetching source from: %s\n") % self.spec.source.archiveUri)
self.sourceArchive.fetch() self.sourceArchive.fetch()
ui.info("Source archive is stored: %s/%s\n" ui.info(_("Source archive is stored: %s/%s\n")
%(config.archives_dir(), self.spec.source.archiveName)) %(config.archives_dir(), self.spec.source.archiveName))
def unpack_source_archive(self): def unpack_source_archive(self):
ui.info("Unpacking archive...") ui.info(_("Unpacking archive..."))
self.sourceArchive.unpack() self.sourceArchive.unpack()
ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir()) ui.info(_(" unpacked (%s)\n") % self.ctx.pkg_work_dir())
self.set_state("unpacked") self.set_state("unpacked")
def run_setup_action(self): def run_setup_action(self):
# Run configure, build and install phase # Run configure, build and install phase
ui.action("Setting up source...\n") ui.action(_("Setting up source...\n"))
self.run_action_function(const.setup_func) self.run_action_function(const.setup_func)
self.set_state("setupaction") self.set_state("setupaction")
def run_build_action(self): def run_build_action(self):
ui.action("Building source...\n") ui.action(_("Building source...\n"))
self.run_action_function(const.build_func) self.run_action_function(const.build_func)
self.set_state("buildaction") self.set_state("buildaction")
def run_install_action(self): def run_install_action(self):
ui.action("Installing...\n") ui.action(_("Installing...\n"))
# Before install make sure install_dir is clean # Before install make sure install_dir is clean
if os.path.exists(self.ctx.pkg_install_dir()): if os.path.exists(self.ctx.pkg_install_dir()):
@@ -178,10 +182,10 @@ class PisiBuild:
buf = open(scriptfile).read() buf = open(scriptfile).read()
exec compile(buf, "error", "exec") in localSymbols, globalSymbols exec compile(buf, "error", "exec") in localSymbols, globalSymbols
except IOError, e: except IOError, e:
ui.error("Unable to read Action Script (%s): %s\n" %(scriptfile,e)) ui.error(_("Unable to read Action Script (%s): %s\n") %(scriptfile,e))
sys.exit(1) sys.exit(1)
except SyntaxError, e: except SyntaxError, e:
ui.error ("SyntaxError in Action Script (%s): %s\n" %(scriptfile,e)) ui.error (_("SyntaxError in Action Script (%s): %s\n") %(scriptfile,e))
sys.exit(1) sys.exit(1)
self.actionLocals = localSymbols self.actionLocals = localSymbols
@@ -212,7 +216,7 @@ class PisiBuild:
self.actionLocals[func]() self.actionLocals[func]()
else: else:
if mandatory: if mandatory:
Error, "unable to call function from actions: %s" %func Error, _("unable to call function from actions: %s") %func
os.chdir(curDir) os.chdir(curDir)
@@ -232,7 +236,7 @@ class PisiBuild:
compressType=patch.compressionType, compressType=patch.compressionType,
targetDir=config.tmp_dir()) targetDir=config.tmp_dir())
ui.action("* Applying patch: %s\n" % patch.filename) ui.action(_("* Applying patch: %s\n") % patch.filename)
util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target) util.do_patch(self.srcDir, patchFile, level=patch.level, target=patch.target)
def gen_metadata_xml(self, package): def gen_metadata_xml(self, package):
@@ -273,7 +277,7 @@ class PisiBuild:
collisions = check_path_collision(package, collisions = check_path_collision(package,
self.spec.packages) self.spec.packages)
if collisions: if collisions:
raise Error('Path collisions detected') raise Error(_('Path collisions detected'))
d = {} d = {}
for pinfo in package.paths: for pinfo in package.paths:
path = install_dir + pinfo.pathname path = install_dir + pinfo.pathname
@@ -362,17 +366,17 @@ class PisiBuild:
self.spec.source.release) self.spec.source.release)
ui.action("** Building package %s\n" % package.name); ui.action(_("** Building package %s\n") % package.name);
ui.action("Generating %s..." % const.files_xml) ui.action(_("Generating %s...") % const.files_xml)
self.gen_files_xml(package) self.gen_files_xml(package)
ui.info(" done.\n") ui.info(_(" done.\n"))
ui.action("Generating %s..." % const.metadata_xml) ui.action(_("Generating %s...") % const.metadata_xml)
self.gen_metadata_xml(package) self.gen_metadata_xml(package)
ui.info(" done.\n") ui.info(_(" done.\n"))
ui.action("Creating PISI package %s\n" % name) ui.action(_("Creating PISI package %s\n") % name)
pkg = Package(name, 'w') pkg = Package(name, 'w')
+28 -35
View File
@@ -12,13 +12,21 @@
import sys import sys
import os import os
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
sys.path.append('.') sys.path.append('.')
import pisi.specfile import pisi.specfile
import pisi.uri import pisi.uri
def echo(string):
print string.encode("utf8")
class Histogram: class Histogram:
def __init__(self): def __init__(self, title):
self.list = {} self.list = {}
self.title = title
def add(self, name): def add(self, name):
if self.list.has_key(name): if self.list.has_key(name):
@@ -39,9 +47,12 @@ class Histogram:
items.sort(self._sortfunc) items.sort(self._sortfunc)
return items return items
def html_out(self):
echo("<h1>%s</h1><table>" % self.title)
for name,cnt in self.get_list():
echo("<tr><td>%s</td><td>%s</td></tr>" % (name, cnt))
echo("</table>")
def echo(string):
print string.encode("utf8")
def scan_pspec(folder): def scan_pspec(folder):
paks = [] paks = []
@@ -67,10 +78,12 @@ def add_deps(deps, spec):
for p in a: for p in a:
deps.add(p) deps.add(p)
hosts = Histogram() hosts = Histogram(_("Source hosts"))
people = Histogram() people = Histogram(_("Packagers"))
licenses = Histogram() licenses = Histogram(_("Licenses"))
components = Histogram() components = Histogram(_("Components"))
dependencies = Histogram(_("Dependencies"))
types = Histogram(_("File types"))
mostp_name = None mostp_name = None
mostp_count = 0 mostp_count = 0
nr_binpaks = 0 nr_binpaks = 0
@@ -78,8 +91,6 @@ nr_patches = 0
maxpy_lines = 0 maxpy_lines = 0
maxpy_name = None maxpy_name = None
paknames = {} paknames = {}
dependencies = Histogram()
types = Histogram()
errors = [] errors = []
@@ -128,7 +139,7 @@ for pak in paks:
print "<html><head><title>%s İstatistikleri</title>" % (sys.argv[1]) print "<html><head><title>%s İstatistikleri</title>" % (sys.argv[1])
print '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' print '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'
print "</head><body>" echo("</head><body>")
print "<p>Toplam %d kod paketi, ve bunlardan oluşturulacak %d ikili paket var.</p>" % (len(paks), nr_binpaks) print "<p>Toplam %d kod paketi, ve bunlardan oluşturulacak %d ikili paket var.</p>" % (len(paks), nr_binpaks)
echo(u"<p>Toplam peç sayısı %d</p>" % nr_patches) echo(u"<p>Toplam peç sayısı %d</p>" % nr_patches)
@@ -146,28 +157,13 @@ if errors != []:
else: else:
print "<p>Hata yok, tebrikler!</p>" print "<p>Hata yok, tebrikler!</p>"
print "<h1>Komponentler</h1><table>" components.html_out()
for name,cnt in components.get_list(): people.html_out()
print "<tr><td>%s</td><td>%s</td></tr>" % (name, cnt) licenses.html_out()
print "</table>" types.html_out()
print "<h1>Paketleyiciler</h1><table>" echo(_("<h1>Dependencies<br>"))
for name,cnt in people.get_list(): echo(_("<small>package name with italics are not available in the repository</small></h1>"))
echo("<tr><td>%s</td><td>%s</td></tr>" % (name, cnt))
print "</table>"
print "<h1>Lisanslar</h1><table>"
for name,cnt in licenses.get_list():
print "<tr><td>%s</td><td>%s</td></tr>" % (name, cnt)
print "</table>"
print "<h1>Dosya tipleri</h1><table>"
for name,cnt in types.get_list():
print "<tr><td>%s</td><td>%s</td></tr>" % (name, cnt)
print "</table>"
echo(u"<h1>Bağımlılıklar<br>")
echo(u"<small>(italik olanlar depoda bulunmayanlar)</small></h1>")
print "<table>" print "<table>"
for name,cnt in dependencies.get_list(): for name,cnt in dependencies.get_list():
if paknames.has_key(name): if paknames.has_key(name):
@@ -176,9 +172,6 @@ for name,cnt in dependencies.get_list():
print "<tr><td><i>%s</i></td><td>%d</td></tr>" % (name, cnt) print "<tr><td><i>%s</i></td><td>%d</td></tr>" % (name, cnt)
print "</table>" print "</table>"
echo(u"<h1>Kod kaynakları</h1><table>") hosts.html_out()
for name,cnt in hosts.get_list():
print "<tr><td>%s</td><td>%s</td></tr>" % (name, cnt)
print "</table>"
print "</body>" print "</body>"