Moved gettext into i18n module.

pull/479/head
Jussi Pakkanen 9 years ago
parent 37d7473615
commit 12a4e7d7e7
  1. 22
      mesonbuild/backend/ninjabackend.py
  2. 6
      mesonbuild/build.py
  3. 14
      mesonbuild/interpreter.py
  4. 29
      mesonbuild/modules/i18n.py
  5. 2
      test cases/frameworks/6 gettext/meson.build
  6. 4
      test cases/frameworks/6 gettext/po/intltest.pot
  7. 3
      test cases/frameworks/6 gettext/po/meson.build

@ -406,17 +406,16 @@ int dummy;
def generate_po(self, outfile):
for p in self.build.pot:
(packagename, languages, subdir) = p
input_file = os.path.join(subdir, 'POTFILES')
input_file = os.path.join(p.subdir, 'POTFILES')
elem = NinjaBuildElement(self.all_outputs, 'pot', 'GEN_POT', [])
elem.add_item('PACKAGENAME', packagename)
elem.add_item('OUTFILE', packagename + '.pot')
elem.add_item('PACKAGENAME', p.packagename)
elem.add_item('OUTFILE', p.packagename + '.pot')
elem.add_item('FILELIST', os.path.join(self.environment.get_source_dir(), input_file))
elem.add_item('OUTDIR', os.path.join(self.environment.get_source_dir(), subdir))
elem.add_item('OUTDIR', os.path.join(self.environment.get_source_dir(), p.subdir))
elem.write(outfile)
for l in languages:
infile = os.path.join(self.environment.get_source_dir(), subdir, l + '.po')
outfilename = os.path.join(subdir, l + '.gmo')
for l in p.languages:
infile = os.path.join(self.environment.get_source_dir(), p.subdir, l + '.po')
outfilename = os.path.join(p.subdir, l + '.gmo')
lelem = NinjaBuildElement(self.all_outputs, outfilename, 'GEN_GMO', infile)
lelem.add_item('INFILE', infile)
lelem.add_item('OUTFILE', outfilename)
@ -482,11 +481,10 @@ int dummy;
def generate_po_install(self, d, elem):
for p in self.build.pot:
(package_name, languages, subdir) = p
# FIXME: assumes only one po package per source
d.po_package_name = package_name
for lang in languages:
rel_src = os.path.join(subdir, lang + '.gmo')
d.po_package_name = p.packagename
for lang in p.languages:
rel_src = os.path.join(p.subdir, lang + '.gmo')
src_file = os.path.join(self.environment.get_build_dir(), rel_src)
d.po.append((src_file, self.environment.coredata.get_builtin_option('localedir'), lang))
elem.add_dep(rel_src)

@ -1016,3 +1016,9 @@ class InstallScript:
def __init__(self, cmd_arr):
assert(isinstance(cmd_arr, list))
self.cmd_arr = cmd_arr
class PoInfo():
def __init__(self, packagename, languages, subdir):
self.packagename = packagename
self.languages = languages
self.subdir = subdir

@ -1039,6 +1039,10 @@ class Interpreter():
self.build.install_scripts.append(v)
elif isinstance(v, build.Data):
self.build.data.append(v)
elif isinstance(v, build.PoInfo):
if len(self.build.pot) > 0:
raise coredata.MesonException('More than one gettext definition currently not supported.')
self.build.pot.append(v)
else:
print(v)
raise InterpreterException('Module returned a value of unknown type.')
@ -1269,15 +1273,7 @@ class Interpreter():
@stringArgs
def func_gettext(self, nodes, args, kwargs):
if len(args) != 1:
raise InterpreterException('Gettext requires one positional argument (package name).')
packagename = args[0]
languages = kwargs.get('languages', None)
check_stringlist(languages, 'Argument languages must be a list of strings.')
# TODO: check that elements are strings
if len(self.build.pot) > 0:
raise InterpreterException('More than one gettext definition currently not supported.')
self.build.pot.append((packagename, languages, self.subdir))
raise InterpreterException('Gettext() function has been moved to module i18n. Import it and use i18n.gettext() instead')
def func_option(self, nodes, args, kwargs):
raise InterpreterException('Tried to call option() in build description file. All options must be in the option file.')

@ -0,0 +1,29 @@
# Copyright 2016 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .. import coredata, mesonlib, build
class I18nModule:
def gettext(self, state, args, kwargs):
if len(args) != 1:
raise coredata.MesonException('Gettext requires one positional argument (package name).')
packagename = args[0]
languages = mesonlib.stringlistify(kwargs.get('languages', []))
if len(languages) == 0:
raise coredata.MesonException('List of languages empty.')
return build.PoInfo(packagename, languages, state.subdir)
def initialize():
return I18nModule()

@ -1,4 +1,6 @@
project('gettext example', 'c')
i18n = import('i18n')
subdir('po')
subdir('src')

@ -1,6 +1,6 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# This file is distributed under the same license as the intltest package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: intltest\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-12 19:04+0300\n"
"POT-Creation-Date: 2016-03-28 19:59+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"

@ -1,4 +1,3 @@
langs = ['fi', 'de']
gettext('intltest',
languages : langs)
i18n.gettext('intltest', languages : langs)

Loading…
Cancel
Save