[PATCH 1/2] Make handling translations easier

Vratislav Podzimek vpodzime at redhat.com
Mon Sep 9 12:09:13 UTC 2013


Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 .tx/config                                |  8 ++--
 MANIFEST.in                               |  3 +-
 Makefile                                  | 20 +++++++-
 initial-setup.spec                        |  4 +-
 locale/cs_CZ/LC_MESSAGES/initial-setup.po | 27 -----------
 locale/initial-setup.pot                  | 26 -----------
 po/Makefile                               | 77 +++++++++++++++++++++++++++++++
 po/initial-setup.pot                      | 41 ++++++++++++++++
 setup.py                                  | 11 -----
 9 files changed, 144 insertions(+), 73 deletions(-)
 delete mode 100644 locale/cs_CZ/LC_MESSAGES/initial-setup.po
 delete mode 100644 locale/initial-setup.pot
 create mode 100644 po/Makefile
 create mode 100644 po/initial-setup.pot

diff --git a/.tx/config b/.tx/config
index 65fbeef..c1c5c47 100644
--- a/.tx/config
+++ b/.tx/config
@@ -1,8 +1,8 @@
 [main]
-host = https://www.transifex.net
+host = https://www.transifex.com
 
 [initial-setup.master]
-file_filter = locale/<lang>/LC_MESSAGES/initial-setup.po
-source_file = locale/initial-setup.pot
+file_filter = po/<lang>.po
+source_file = po/initial-setup.pot
 source_lang = en
-type = PO
\ No newline at end of file
+
diff --git a/MANIFEST.in b/MANIFEST.in
index 48af4cd..60d27e6 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,7 +1,8 @@
 include COPYING
+include Makefile
 recursive-include systemd *
 recursive-include scripts *
-recursive-include locale *.po *.pot
+recursive-include po *.po *.pot Makefile
 recursive-include modules *.py *.glade *.txt
 recursive-include initial_setup *.py *.glade *.txt
 recursive-exclude modules *.pyc *.pyo
diff --git a/Makefile b/Makefile
index 8264080..f890124 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-# Makefile.am for anaconda
+# Taken from the anaconda sources
 #
-# Copyright (C) 2009  Red Hat, Inc.
+# Copyright (C) 2009-2013  Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU Lesser General Public License as published
@@ -20,6 +20,13 @@
 ANACONDA_PATH=${HOME}/Work/anaconda/msivak
 PYKICKSTART_PATH=${HOME}/Work/pykickstart/master
 
+default: all
+
+all: po-files
+
+po-files:
+	$(MAKE) -C po
+
 # GUI TESTING
 rungui:
 	ANACONDA_DATA=${ANACONDA_PATH}/data \
@@ -65,3 +72,12 @@ runpy:
 	GLADE_CATALOG_SEARCH_PATH=${ANACONDA_PATH}/widgets/glade \
 	GLADE_MODULE_SEARCH_PATH=${ANACONDA_PATH}/widgets/src/.libs \
 	ipython
+
+potfile:
+	$(MAKE) -C po potfile
+
+po-pull:
+	tx pull -a --disable-overwrite
+
+install-po-files:
+	$(MAKE) -C po install
diff --git a/initial-setup.spec b/initial-setup.spec
index a3bb6db..8304044 100644
--- a/initial-setup.spec
+++ b/initial-setup.spec
@@ -25,7 +25,6 @@ BuildRequires: gtk-doc
 BuildRequires: gobject-introspection-devel
 BuildRequires: glade-devel
 BuildRequires: pygobject3
-BuildRequires: python-babel
 BuildRequires: anaconda >= 19.13
 BuildRequires: python-di
 Requires: gtk3
@@ -51,13 +50,14 @@ rm -rf *.egg-info
 
 %build
 %{__python} setup.py build
-%{__python} setup.py compile_catalog -D %{name} -d locale
+make po-files
 
 %check
 %{__python} setup.py nosetests
 
 %install
 %{__python} setup.py install --skip-build --root $RPM_BUILD_ROOT
+make install-po-files
 %find_lang %{name}
 
 %post
diff --git a/locale/cs_CZ/LC_MESSAGES/initial-setup.po b/locale/cs_CZ/LC_MESSAGES/initial-setup.po
deleted file mode 100644
index 189caf7..0000000
--- a/locale/cs_CZ/LC_MESSAGES/initial-setup.po
+++ /dev/null
@@ -1,27 +0,0 @@
-# Czech (Czech Republic) translations for initial-setup.
-# Copyright (C) 2013 Red Hat
-# This file is distributed under the same license as the initial-setup
-# project.
-# Martin Sivák <msivak at redhat.com>, 2013.
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: initial-setup 0.1\n"
-"Report-Msgid-Bugs-To: EMAIL at ADDRESS\n"
-"POT-Creation-Date: 2013-01-11 15:10+0100\n"
-"PO-Revision-Date: 2013-01-11 15:12+0100\n"
-"Last-Translator: Martin Sivák <msivak at redhat.com>\n"
-"Language-Team: cs_CZ <LL at li.org>\n"
-"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
-"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Generated-By: Babel 0.9.6\n"
-
-#: initial_setup/gui/gui.py:20
-msgid ""
-"Are you sure you want to quit the configuration process?\n"
-"You might end up with unusable system if you do."
-msgstr "Opravdu chcete ukončit konfiguraci?\nSystém může zůstat nepoužitelný, pokud to uděláte."
-
diff --git a/locale/initial-setup.pot b/locale/initial-setup.pot
deleted file mode 100644
index 08b2dec..0000000
--- a/locale/initial-setup.pot
+++ /dev/null
@@ -1,26 +0,0 @@
-# Translations template for initial-setup.
-# Copyright (C) 2013 ORGANIZATION
-# This file is distributed under the same license as the initial-setup
-# project.
-# FIRST AUTHOR <EMAIL at ADDRESS>, 2013.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: initial-setup 0.1\n"
-"Report-Msgid-Bugs-To: EMAIL at ADDRESS\n"
-"POT-Creation-Date: 2013-01-17 14:38+0100\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
-"Language-Team: LANGUAGE <LL at li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=utf-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Generated-By: Babel 0.9.6\n"
-
-#: initial_setup/gui/gui.py:20
-msgid ""
-"Are you sure you want to quit the configuration process?\n"
-"You might end up with unusable system if you do."
-msgstr ""
-
diff --git a/po/Makefile b/po/Makefile
new file mode 100644
index 0000000..febb30a
--- /dev/null
+++ b/po/Makefile
@@ -0,0 +1,77 @@
+#
+# taken from python-meh sources
+# Makefile for the PO files (translation) catalog
+#
+# $Id$
+
+TOP	 = ../..
+
+# What is this package?
+NLSPACKAGE	= initial-setup
+POTFILE		= $(NLSPACKAGE).pot
+INSTALL		= /usr/bin/install -c
+INSTALL_DATA	= $(INSTALL) -m 644
+INSTALL_DIR	= /usr/bin/install -d
+
+# destination directory
+INSTALL_NLS_DIR = $(RPM_BUILD_ROOT)/usr/share/locale
+
+# PO catalog handling
+MSGMERGE	= msgmerge -v
+XGETTEXT	= xgettext --default-domain=$(NLSPACKAGE) \
+		  --add-comments
+MSGFMT		= msgfmt --statistics --verbose
+
+# What do we need to do
+POFILES		= $(wildcard *.po)
+MOFILES		= $(patsubst %.po,%.mo,$(POFILES))
+PYSRC		= $(wildcard ../initial_setup/*.py ../initial_setup/*/*.py ../initial_setup/*/*/*.py)
+GLADEFILES = $(wildcard ../initial_setup/*/*/*.glade)
+
+all::  update-po $(MOFILES)
+
+potfile: $(PYSRC) glade-po
+	$(XGETTEXT) -L Python --keyword=_ --keyword=N_ $(PYSRC) tmp/*.h
+	@if cmp -s $(NLSPACKAGE).po $(POTFILE); then \
+	    rm -f $(NLSPACKAGE).po; \
+	else \
+	    mv -f $(NLSPACKAGE).po $(POTFILE); \
+	fi; \
+
+glade-po: $(GLADEFILES)
+	rm -rf tmp/
+	for f in $(GLADEFILES); do \
+		intltool-extract --type=gettext/glade -l $$f ;\
+	done
+
+update-po: Makefile refresh-po
+
+refresh-po: Makefile
+	for cat in $(POFILES); do \
+		lang=`basename $$cat .po`; \
+		if $(MSGMERGE) $$lang.po $(POTFILE) > $$lang.pot ; then \
+			mv -f $$lang.pot $$lang.po ; \
+			echo "$(MSGMERGE) of $$lang succeeded" ; \
+		else \
+			echo "$(MSGMERGE) of $$lang failed" ; \
+			rm -f $$lang.pot ; \
+		fi \
+	done
+
+clean:
+	@rm -fv *mo *~ .depend
+	@rm -rf tmp
+
+install: $(MOFILES)
+	@for n in $(MOFILES); do \
+	    l=`basename $$n .mo`; \
+	    $(INSTALL_DIR) $(INSTALL_NLS_DIR)/$$l/LC_MESSAGES; \
+	    $(INSTALL_DATA) --verbose $$n $(INSTALL_NLS_DIR)/$$l/LC_MESSAGES/$(NLSPACKAGE).mo; \
+	done
+
+%.mo: %.po
+	$(MSGFMT) -o $@ $<
+
+.PHONY: missing depend
+
+
diff --git a/po/initial-setup.pot b/po/initial-setup.pot
new file mode 100644
index 0000000..bdc3e22
--- /dev/null
+++ b/po/initial-setup.pot
@@ -0,0 +1,41 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2013-09-09 12:57+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: ../initial_setup/tui/tui.py:15 ../initial_setup/gui/gui.py:17
+msgid ""
+"Are you sure you want to quit the configuration process?\n"
+"You might end up with unusable system if you do."
+msgstr ""
+
+#: ../initial_setup/tui/hubs/initial_setup_hub.py:37
+#, python-format
+msgid "Initial setup of %(product)s"
+msgstr ""
+
+#: ../initial_setup/tui/hubs/initial_setup_hub.py:39
+msgid "Initial setup"
+msgstr ""
+
+#: tmp/initial_setup.glade.h:1
+msgid "_QUIT"
+msgstr ""
+
+#: tmp/initial_setup.glade.h:2
+msgid "_FINISH CONFIGURATION"
+msgstr ""
diff --git a/setup.py b/setup.py
index 0b5757d..b1e0ca7 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,6 @@
 
 import os
 from setuptools import setup, find_packages
-from babel.messages import frontend as babel
 from glob import *
 
 # Utility function to read the README file.
@@ -36,12 +35,6 @@ def read(fname):
 data_files = [('/usr/lib/systemd/system', glob('systemd/*.service')),
               ('/usr/share/initial-setup/modules', glob('modules/*'))]
 
-# add localization files
-data_files += [('/usr/share/locale/%s/LC_MESSAGES' % dirname,
-                ['locale/%s/LC_MESSAGES/initial-setup.mo' % dirname])
-                for dirname in os.listdir("locale")
-                if not dirname.endswith(".pot")]
-
 # add the firstboot start script for s390 architectures
 if os.uname()[4].startswith('s390'):
     data_files.append(('/etc/profile.d', ['scripts/initial-setup.sh']))
@@ -73,8 +66,4 @@ setup(
         "Topic :: System :: Systems Administration",
         "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
     ],
-    cmdclass = {'compile_catalog': babel.compile_catalog,
-                'extract_messages': babel.extract_messages,
-                'init_catalog': babel.init_catalog,
-                'update_catalog': babel.update_catalog}
 )
-- 
1.8.3.1



More information about the anaconda-patches mailing list