Skip to content

Commit

Permalink
Add support to copy designated translation files (foo.po and foo.mo)
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Sep 2, 2009
1 parent 414a118 commit a45a1b0
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bundler/bundler.py
Expand Up @@ -454,6 +454,30 @@ def copy_icon_themes(self):
cmd = "gtk-update-icon-cache -f " + path + " 2>/dev/null"
os.popen(cmd)

def copy_translations(self):
translations = self.project.get_translations()
prefix = self.project.get_prefix()
for program in translations:
source = self.project.evaluate_path(program.source)


def name_filter(filename):
path, fname = os.path.split(filename)
name, ext = os.path.splitext(fname)
if name != program.name:
return False
elif ext not in (".mo", ".po"):
return False
else:
return True

for root, trees, files in os.walk(source):
for file in filter(name_filter, files):
path = os.path.join(root, file)
self.copy_path(Path("${prefix}" + path[len(prefix):],
program.dest))


def run(self):
# Remove the temp location forcefully.
path = self.project.evaluate_path(self.bundle_path)
Expand Down Expand Up @@ -497,6 +521,9 @@ def run(self):
# Data
for path in self.project.get_data():
self.copy_path(path)

# Translaations
self.copy_translations()

# Frameworks
frameworks = self.project.get_frameworks()
Expand Down
27 changes: 27 additions & 0 deletions bundler/project.py
Expand Up @@ -151,6 +151,26 @@ def from_node(cls, node):
return binary
from_node = classmethod(from_node)

class Translation(Path):
def __init__(self, name, sourcepath, destpath):
Path.__init__(self, sourcepath, destpath)
self.name = name

def from_node(cls, node):
source = utils.node_get_string(node)
dest = node.getAttribute("dest")
if len(dest) == 0:
dest = None
name = node.getAttribute("name")
if len(name) == 0:
raise "The tag 'translations' must have a 'name' property"

return Translation(name, source, dest)
from_node = classmethod(from_node)




class Data(Path):
pass

Expand Down Expand Up @@ -309,6 +329,13 @@ def get_frameworks(self):
frameworks.append(Framework.from_node(node))
return frameworks

def get_translations(self):
translations = []
nodes = utils.node_get_elements_by_tag_name(self.root, "translations")
for node in nodes:
translations.append(Translation.from_node(node))
return translations

def get_main_binary(self):
node = utils.node_get_element_by_tag_name(self.root, "main-binary")
if not node:
Expand Down
10 changes: 10 additions & 0 deletions bundler/project_test.py
Expand Up @@ -165,4 +165,14 @@ def test_o_get_data(self):
"${bundle}/Contents/Resources/etc/gtk-2.0/gtkrc",
"Data[2] Destination %s" % data[2].dest)

def test_p_get_translations(self):
trans = self.goodproject.get_translations()
self.failUnlessEqual(len(trans), 1,
"Wrong number of translations %d" % len(trans))
self.failUnlessEqual(trans[0].name, "foo",
"Bad translation name %s" % trans[0].name)
self.failUnlessEqual(trans[0].source, "${prefix}/share/locale",
"Bad translation source %s" % trans[0].source)



13 changes: 13 additions & 0 deletions examples/gtk-demo.bundle
Expand Up @@ -61,6 +61,19 @@
${prefix}/lib/gtk-2.0/${pkg:gtk+-2.0:gtk_binary_version}/loaders/*.so
</binary -->

<!-- Translation filenames, one for each program or library that you
want to copy in to the bundle. The "dest" attribute is
optional, as usual. Bundler will find all translations of that
library/program under the indicated directory and copy them.-->
<translations dest="${bundle}/Contents/Resources" name="gtk20">
${prefix}/share/locale
</translations>

<translations dest="${bundle}/Contents/Resources" name="gtk20">
${prefix}/share/locale
</translations>


<!-- Data to copy in, usually Glade/UI files, images, sounds files
etc. The destination inside the bundle can be specified if the
files should end up at a different location, by using the
Expand Down
3 changes: 3 additions & 0 deletions test/goodproject.bundle
Expand Up @@ -43,5 +43,8 @@
<icon-theme icons="auto">
Tango
</icon-theme>
<translations name="foo">
${prefix}/share/locale
</translations>

</app-bundle>

0 comments on commit a45a1b0

Please sign in to comment.