Verified Commit 2d386aca authored by Štěpán Henek's avatar Štěpán Henek 🌩

compile translations via babel + version handling without git

parent d8159ee6
......@@ -23,7 +23,7 @@ COMPILED_L10N = $(wildcard foris/locale/*/LC_MESSAGES/*.mo)
SASS_COMPILER = compass compile -s compressed -e production
all: branding sass localization
all: branding sass
# target: branding - Copy assets for a specified device to its location.
branding:
......@@ -39,13 +39,6 @@ sass:
$(SASS_COMPILER)
@echo
# target: localization - Create .mo files from .po fiels in locale directory
localization:
@echo "-- Compiling localization files"
@tools/compilemessages.sh foris
@echo "Done."
@echo
# target: clean - Remove all compiled CSS and localization files.
clean:
rm -rf $(COMPILED_CSS) $(COMPILED_L10N) $(TPL_FILES)
......
import os
# this file is automatically updated when distutils are running the setup
__version__ = "unknown"
__version__ = "98.2"
# variable used to enable some device-specific features
DEVICE_CUSTOMIZATION = "turris" # should be either "turris" or "omnia"
......
from distutils.core import setup
#!/usr/bin/env python
import os
import re
import subprocess
import foris
from setuptools import setup
from setuptools.command.build_py import build_py
from foris import __version__
def update_version_file(version_file_path, version_number):
"""Read file containing version variable and update it to version_number."""
with open(version_file_path, "r") as f:
content = f.readlines()
with open(version_file_path, "w") as f:
version_re = re.compile(r'^__version__ = "[^"]*"')
for line in content:
f.write(version_re.sub('__version__ = "%s"' % version_number, line))
class BuildCmd(build_py):
def run(self):
# compile translation
from babel.messages import frontend as babel
cmd = babel.compile_catalog()
cmd.initialize_options()
cmd.directory = os.path.join(os.path.dirname(__file__), "foris", "locale")
cmd.finalize_options()
cmd.run()
def get_version(update_file=True):
"""Get version from Git tags, optionally save it to foris module."""
base_dir = os.path.dirname(os.path.abspath(__file__))
if not os.path.isdir(os.path.join(base_dir, ".git")):
if foris.__version__ != "unknown":
# fallback to stored version (e.g. when making package)
return foris.__version__
return "unknown"
p = subprocess.Popen(["git", "describe", "--tags", "--dirty"], stdout=subprocess.PIPE)
stdout = p.communicate()[0].strip()
# correct tags with version must start with "package-v"
assert stdout.startswith("package-v")
version_number = stdout[len("package-v"):]
if update_file:
init_file = os.path.join(base_dir, "foris", "__init__.py")
update_version_file(init_file, version_number)
return version_number
# run original build cmd
build_py.run(self)
setup(
name="Foris",
version=get_version(),
version=__version__,
description="Web administration interface for OpenWrt based on NETCONF",
author="CZ.NIC, z. s. p. o.",
author_email="stepan.henek@nic.cz",
......@@ -46,7 +33,9 @@ setup(
requires=[
"bottle",
"bottle_i18n",
"ncclient",
],
setup_requires=[
'babel',
],
provides=[
"foris"
......@@ -76,4 +65,7 @@ setup(
"utils/*.pickle2",
]
},
cmdclass={
"build_py": BuildCmd,
}
)
#!/bin/bash
# Foris - web administration interface for OpenWrt based on NETCONF
# Copyright (C) 2013 CZ.NIC, z.s.p.o. <http://www.nic.cz>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
shopt -s extglob
for lang_dir in $1/locale/??; do
locale_dir=${lang_dir}/LC_MESSAGES
files=$(find ${locale_dir} -name "*.po" -not -name "messages.po")
msgcat ${files} > ${locale_dir}/messages.po
echo "Compiling translation files in $lang_dir."
msgfmt ${locale_dir}/messages.po -o ${locale_dir}/messages.mo
done
echo "All messages compiled."
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment