Skip to content

Commit

Permalink
Update translation (#47)
Browse files Browse the repository at this point in the history
- Move translation sources to po
- Add functions to generate .mo files
  • Loading branch information
hsbasu authored Mar 2, 2024
1 parent 597a736 commit 56f3c8d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion battery-monitor.pot → po/battery-monitor.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-23 10:47+0530\n"
"POT-Creation-Date: 2024-03-02 13:12+0530\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"
Expand Down
35 changes: 28 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import glob
import os
import subprocess

from setuptools import setup
from subprocess import check_output
Expand All @@ -18,10 +19,30 @@
version = version.split('~')[0]
f.write("%s" % version)

setup(
data_files=[('share/battery-monitor/ui', glob.glob("data/ui/*")),
('share/applications', glob.glob("data/applications/*.desktop")),
('share/icons/hicolor/scalable/apps', glob.glob("data/icons/*")),
('share/glib-2.0/schemas', glob.glob("data/*.xml")),
]
gschema_dir_suffix = 'share/glib-2.0/schemas'

data_files = [('share/applications', glob.glob("data/applications/*.desktop")),
('share/icons/hicolor/scalable/apps', glob.glob("data/icons/*")),
(gschema_dir_suffix, glob.glob("data/schema/*.xml"))
]

def create_mo_files():
po_files = glob.glob("po/*.po")
prefix = 'battery-monitor'

for po_file in po_files:
po_name = os.path.splitext(os.path.split(po_file)[1])[0]
replace_txt = "%s-" % prefix
lang = po_name.replace(replace_txt, '')
os.makedirs("data/locale/%s" % lang, exist_ok=True)
mo = "data/locale/%s/%s.mo" % (lang, prefix)
subprocess.run(['msgfmt', '-o', str(mo), po_file], check=True)

mo_file = map(lambda i: ('share/locale/%s/LC_MESSAGES' % lang, [i+'/%s.mo' % prefix]), glob.glob('data/locale/%s' % lang))
data_files.extend(mo_file)

create_mo_files()

setup(data_files=data_files,
# cmdclass = {'install_data': install_data}
)
2 changes: 1 addition & 1 deletion update-pot
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
xgettext --keyword=_ --keyword=N_ --output=battery-monitor.pot -f POTFILES.in
xgettext --keyword=_ --keyword=N_ --output=po/battery-monitor.pot -f po/POTFILES.in

0 comments on commit 56f3c8d

Please sign in to comment.