Skip to content

Commit

Permalink
Translate HTML templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf committed Jan 23, 2025
1 parent ef70b47 commit 5ae259e
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ po/Makefile.in.in
po/POTFILES
po/liferea.pot
po/stamp-it
js/*.xml
resources/*.xml
src/js.c
src/js.h
src/dbus_wrap.c
Expand Down
3 changes: 0 additions & 3 deletions config.h.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* always defined to indicate that i18n is enabled */
#define ENABLE_NLS @ENABLE_NLS@

/* gettext domain */
#define GETTEXT_PACKAGE @GETTEXT_PACKAGE@

/* Name of package */
#define PACKAGE @PACKAGE@

Expand Down
13 changes: 4 additions & 9 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
project('liferea', 'c',
version: '2.0',
meson_version: '>= 0.59.0'
meson_version: '>= 0.62.0'
)

gnome = import('gnome')
i18n = import('i18n')

gettext_package = 'liferea'
add_project_arguments('-DGETTEXT_PACKAGE=' + gettext_package, language: 'c')
subdir('po')

prefix = get_option('prefix')
Expand All @@ -25,7 +27,6 @@ conf.set_quoted('PACKAGE_DATA_DIR', datadir)
conf.set_quoted('PACKAGE_LIB_DIR', libdir)
conf.set_quoted('PACKAGE_LOCALE_DIR', localedir)
conf.set_quoted('VERSION', meson.project_version())
conf.set_quoted('GETTEXT_PACKAGE', 'liferea')
conf.set('ENABLE_NLS', 1)

configure_file(
Expand All @@ -34,6 +35,7 @@ configure_file(
configuration: conf
)

subdir('resources')
subdir('src')

liferea_deps = [
Expand All @@ -51,20 +53,13 @@ liferea_deps = [
dependency('fribidi', version: '>= 0.19.7')
]

liferea_resources = gnome.compile_resources(
'resources', 'resources/gresource.xml',
source_dir : 'resources',
c_name : 'liferea_resources'
)

executable('liferea',
liferea_sources,
liferea_resources,
dependencies: liferea_deps,
include_directories: include_directories('.', 'src')
)


# Introspection
#if get_option('introspection')
# gir = gnome.generate_gir('Liferea-3.0',
Expand Down
2 changes: 1 addition & 1 deletion po/meson.build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
i18n.gettext('liferea', preset: 'glib')
i18n_result = i18n.gettext(gettext_package, preset: 'glib')
66 changes: 66 additions & 0 deletions resources/i18n-filter.xslt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0"?>

<!--
/**
* Localization stylesheet for Liferea
*
* Copyright (C) 2006 Aristotle Pagaltzis <[email protected]>
*
* 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.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-->

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- the locale to use -->
<xsl:param name="lang" /> <!-- e.g. "de_AT" -->
<xsl:param name="shortlang" /> <!-- e.g. "de" -->

<!-- identity copy -->
<xsl:template match="node()|@*|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- drop elements that have an @xml:lang attribute but with
the wrong value -->
<xsl:template match="*[ @xml:lang ]">
<xsl:if test="@xml:lang = $lang or @xml:lang = $shortlang">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

<xsl:key
name="translations"
match="*[ @xml:lang ]"
use="preceding-sibling::*[ not( @xml:lang ) ][1]"
/>

<!-- handling for the untranslated nodes (can be dropped if there
is a node with a translation) -->
<xsl:template match="*[ not( @xml:lang ) ]">
<xsl:if test="not( key( 'translations', . )[ @xml:lang = $lang or @xml:lang = $shortlang ] )">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
35 changes: 35 additions & 0 deletions resources/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
liferea_resources = gnome.compile_resources(
'resources', 'gresource.xml',
source_dir : '.',
c_name : 'liferea_resources',
dependencies : [
custom_target(
input: 'item.xml.in',
output: 'item.xml',
command: [
find_program('intltool-merge'),
'-x',
'-u',
'-c',
join_paths(meson.project_source_root(), 'po/.intltool-merge-cache'),
join_paths(meson.project_source_root(), 'po'),
'@INPUT@',
'@OUTPUT@',
]
),
custom_target(
input: 'node.xml.in',
output: 'node.xml',
command: [
find_program('intltool-merge'),
'-x',
'-u',
'-c',
join_paths(meson.project_source_root(), 'po/.intltool-merge-cache'),
join_paths(meson.project_source_root(), 'po'),
'@INPUT@',
'@OUTPUT@',
]
)
]
)
2 changes: 1 addition & 1 deletion src/liferea_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ liferea_application_init (LifereaApplication *self)
_("Print debugging messages for the given topic"),
&self->debug_flags,
NULL);
g_option_group_set_translation_domain(debug, GETTEXT_PACKAGE);
g_option_group_set_translation_domain(debug, PACKAGE);
g_option_group_add_entries (debug, debug_entries);

g_application_add_main_option_entries (G_APPLICATION (self), entries);
Expand Down
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ main (int argc, char *argv[])
#endif

#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (PACKAGE, "UTF-8");
textdomain (PACKAGE);
#endif

return liferea_application_new (argc, argv);
Expand Down

0 comments on commit 5ae259e

Please sign in to comment.