Skip to content
Permalink
Browse files

include appinfo metadata file in translation

  • Loading branch information
jef-n committed Sep 25, 2018
1 parent 8e845b9 commit 52a80d895c45876bfdf97d194c7f666031412b5d
@@ -20,22 +20,36 @@ MACRO(ADD_TRANSLATION_FILES _sources )
ENDMACRO(ADD_TRANSLATION_FILES)

# make sure the output directory exists
file(MAKE_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/i18n)
FILE(MAKE_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/i18n)

SET(TS_FILES qgis_ar.ts qgis_bg.ts qgis_bs.ts qgis_ca.ts qgis_cs.ts qgis_da.ts qgis_de.ts qgis_el.ts qgis_eo.ts qgis_es.ts qgis_et.ts qgis_eu.ts qgis_fi.ts qgis_fr.ts qgis_gl.ts qgis_hi.ts qgis_hu.ts qgis_id.ts qgis_is.ts qgis_it.ts qgis_ja.ts qgis_km.ts qgis_ko.ts qgis_ky.ts qgis_lt.ts qgis_lv.ts qgis_nb.ts qgis_nl.ts qgis_pl.ts qgis_pt_BR.ts qgis_pt_PT.ts qgis_ro.ts qgis_ru.ts qgis_sl.ts qgis_sv.ts qgis_tr.ts qgis_uk.ts qgis_vi.ts qgis_zh-Hans.ts qgis_zh-Hant.ts)

ADD_TRANSLATION_FILES (QM_FILES ${TS_FILES})

IF (CMAKE_SYSTEM_NAME STREQUAL "Linux")
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_BINARY_DIR}/org.qgis.qgis.desktop ${CMAKE_BINARY_DIR}/org.qgis.qgis.appdata.xml
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMAND ${PYTHON_EXECUTABLE}
ARGS ${CMAKE_SOURCE_DIR}/scripts/ts2appinfo.py "${CMAKE_BINARY_DIR}"
COMMENT "Updating appinfo files..."
DEPENDS ${QM_FILES}
)

SET(MD_FILES ${CMAKE_BINARY_DIR}/org.qgis.qgis.desktop ${CMAKE_BINARY_DIR}/org.qgis.qgis.appdata.xml)

INSTALL(FILES ${CMAKE_BINARY_DIR}/org.qgis.qgis.desktop DESTINATION share/applications)
INSTALL(FILES ${CMAKE_BINARY_DIR}/org.qgis.qgis.appdata.xml DESTINATION share/metainfo)
ENDIF (CMAKE_SYSTEM_NAME STREQUAL "Linux")

# creating a custom target is needed to make the files build
# "ALL" means that it will be run by default
ADD_CUSTOM_TARGET (translations ALL
DEPENDS ${QM_FILES})
ADD_CUSTOM_TARGET (translations ALL DEPENDS ${QM_FILES} ${MD_FILES})

# first compile sources, then compile translations
IF (WITH_DESKTOP)
ADD_DEPENDENCIES (translations ${QGIS_APP_NAME})
ENDIF (WITH_DESKTOP)


INSTALL (FILES ${QM_FILES}
DESTINATION ${QGIS_DATA_DIR}/i18n)
@@ -1,7 +1,3 @@
#metadata
install(FILES org.qgis.qgis.desktop DESTINATION share/applications)
install(FILES org.qgis.qgis.appdata.xml DESTINATION share/metainfo)

#icons
## application icon
install(FILES ${CMAKE_SOURCE_DIR}/images/icons/qgis_icon.svg RENAME qgis.svg DESTINATION share/icons/hicolor/scalable/apps)

This file was deleted.

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop">
<id>org.qgis.qgis.desktop</id>
<name>QGIS Desktop</name>
<summary>A Free and Open Source Geographic Information System</summary>
<screenshots>
<screenshot><image type="source">https://qgis.org/en/_static/images/about-screenshot.png</image></screenshot>
</screenshots>
<description><p>QGIS is a user friendly Open Source Geographic Information System (GIS) licensed under the GNU General Public License. QGIS is an official project of the Open Source Geospatial Foundation (OSGeo). It runs on Linux, Unix, Mac OSX, Windows and Android and supports numerous vector, raster, and database formats and functionalities.</p></description>

<metadata_license>MIT</metadata_license>
<project_license>GPL-2.0+</project_license>
<url type="bugtracker">https://issues.qgis.org/projects/qgis/issues/</url>
<url type="donation">https://qgis.org/en/site/getinvolved/donations.html</url>
<url type="faq">https://qgis.org/en/site/getinvolved/faq/index.html</url>
<url type="help">https://qgis.org/en/docs/index.html</url>
<url type="homepage">https://qgis.org</url>

<project_group>QGIS</project_group>
<releases>
<release version="3.2.0" date="2018-06-22" />
</releases>
<launchable type="desktop-id">org.qgis.qgis.desktop</launchable>
<provides>
<binary>qgis</binary>
</provides>
</component>

This file was deleted.

@@ -0,0 +1,12 @@
[Desktop Entry]
Type=Application
Name=QGIS Desktop
GenericName=Geographic Information System
Icon=qgis
TryExec=qgis
Exec=qgis %F
Terminal=false
StartupNotify=false
Categories=Qt;Education;Science;Geography;
MimeType=application/x-qgis-project;application/x-qgis-layer-settings;application/x-qgis-layer-definition;application/x-qgis-composer-template;image/tiff;image/jpeg;image/jp2;application/x-raster-aig;application/x-raster-ecw;application/x-raster-mrsid;application/x-mapinfo-mif;application/x-esri-shape;
Keywords=map;globe;postgis;wms;wfs;ogc;osgeo;
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
/***************************************************************************
appinfo2cpp.py
-------------------
begin : 2018-09-24
copyright : (C) 2018 by Jürgen E. Fischer
email : jef at norbit dot de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""

import sys
from xml.etree import ElementTree as et

strings = {}

d = et.parse('linux/org.qgis.qgis.appdata.xml.in')

r = d.getroot()
for elem in ['name', 'summary', 'description']:
for c in r.iter(elem):
if not c.attrib:
l = list(c)
t = c.text if not l else "".join([et.tostring(x).decode("utf-8") for x in l])
strings[t] = 1

f = open("linux/org.qgis.qgis.desktop.in", "r")

for r in f.readlines():
r = r.strip()
if r.startswith("Name="):
strings[r[5:]] = 1
elif r.startswith("GenericName="):
strings[r[12:]] = 1

f.close()

print("""
/*
This is NOT a proper c++ source code. This file is only designed to be caught
by qmake and included in lupdate. It contains all translateable strings collected
by pylupdate5.
*/
""")

for k in strings:
k = k.replace('"', '\\"')
k = k.replace('\n', '\\n')
print("translate( \"appinfo\", \"{}\" )".format(k))
@@ -163,7 +163,7 @@ ($$)

print "Updating changelog...\n";
run( "scripts/create_changelog.sh", "create_changelog.sh failed" );
run( "perl -i -pe 's#<releases>#<releases>\n <release version=\"$newmajor.$newminor.$newpatch\" date=\"" . strftime("%Y-%m-%d", localtime) . "\" />#' linux/org.qgis.qgis.appdata.xml", "appdata update failed" );
run( "perl -i -pe 's#<releases>#<releases>\n <release version=\"$newmajor.$newminor.$newpatch\" date=\"" . strftime("%Y-%m-%d", localtime) . "\" />#' linux/org.qgis.qgis.appdata.xml.in", "appdata update failed" );

unless( $dopoint ) {
run( "scripts/update-news.pl $newmajor $newminor '$newreleasename'", "could not update news" ) if $major>2 || ($major==2 && $minor>14);
@@ -42,7 +42,7 @@ images/themes/default/mIconJoinHasNotUpsertOnEdit.svg
images/themes/default/mIconJoinNotEditable.svg
images/themes/default/mIconJoinedLayerNotEditable.svg
LexerR.py
linux/org.qgis.qgis.appdata.xml
linux/org.qgis.qgis.appdata.xml.in
python/plugins/MetaSearch/resources/connections-default.xml
python/plugins/processing/algs/grass7/description/i.landsat.toar.txt
python/plugins/processing/gui/algnames.txt
@@ -0,0 +1,108 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
/***************************************************************************
ts2appinfo.py
-------------------
begin : 2018-09-24
copyright : (C) 2018 by Jürgen E. Fischer
email : jef at norbit dot de
***************************************************************************/
/***************************************************************************
* *
* 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""

import sys
import os
from glob import glob
from xml.etree import ElementTree as et
from PyQt5.QtCore import QCoreApplication, QTranslator

strings = {}

d = et.parse('linux/org.qgis.qgis.appdata.xml.in')

r = d.getroot()
for elem in ['name', 'summary', 'description']:
for c in r.iter(elem):
if not c.attrib:
l = list(c)
t = c.text if not l else "".join([et.tostring(x).decode("utf-8") for x in l])
strings[t] = {}
else:
r.remove(c)

f = open("linux/org.qgis.qgis.desktop.in", "r")
lines = f.readlines()

for line in lines:
line = line.strip()
for prefix in ['Name', 'GenericName']:
if line.startswith(prefix + "="):
strings[line[len(prefix) + 1:]] = {}

f.close()

try:
argvb = list(map(os.fsencode, sys.argv))
except AttributeError:
argvb = sys.argv

app = QCoreApplication(argvb)

for qm in glob(sys.argv[1] + "/output/i18n/qgis_*.qm"):
translator = QTranslator()
translator.load(qm)

lang = qm[len(sys.argv[1] + "/output/i18n/qgis_"):-3]

for s in strings:
translation = translator.translate("appinfo", s, "")
if translation in [s, '']:
continue
strings[s][lang] = translation

for elem in ['name', 'summary', 'description']:
for c in r.iter(elem):
if c.attrib:
continue

l = list(c)
s = c.text if not l else "".join([et.tostring(x).decode("utf-8") for x in l])

for lang in strings[s]:
e = et.Element(elem, attrib={"xml:lang": lang})
e.text = strings[s][lang]
e.tail = c.tail
r.append(e)

d.write(sys.argv[1] + "/org.qgis.qgis.appdata.xml", encoding="UTF-8", xml_declaration=True)

f = open(sys.argv[1] + "/org.qgis.qgis.desktop", "w")

for line in lines:
skip = False
for prefix in ['Name', 'GenericName']:
if line.startswith(prefix + "="):
skip = True
f.write(line)

t = line.strip()[len(prefix) + 1:]
for lang in strings[t]:
f.write("{}[{}]={}\n".format(prefix, lang, strings[t][lang]))

elif line.startswith(prefix + "["):
skip = True
continue

if not skip:
f.write(line)

f.close()
@@ -39,6 +39,7 @@ cleanup() {
python/plugins/*/python-i18n.{ts,cpp} \
python/plugins/processing/processing-i18n.{ts,cpp} \
src/plugins/grass/grasslabels-i18n.cpp \
src/app/appinfo-i18n.cpp \
i18n/backup.tar \
qgis_ts.pro
do
@@ -165,6 +166,9 @@ perl scripts/qgm2cpp.pl >src/plugins/grass/grasslabels-i18n.cpp
echo Updating processing translations
perl scripts/processing2cpp.pl python/plugins/processing/processing-i18n.cpp

echo Updating appinfo files
python scripts/appinfo2cpp.py >src/app/appinfo-i18n.cpp

echo Creating qmake project file
$QMAKE -project -o qgis_ts.pro -nopwd $PWD/src $PWD/python $PWD/i18n $textcpp

0 comments on commit 52a80d8

Please sign in to comment.
You can’t perform that action at this time.