Skip to content

Commit

Permalink
Fix translations in Quicklook plugin
Browse files Browse the repository at this point in the history
The hack in 9f59728 doesn't work anymore, so instead copy translations into
PoeditQuicklook.qlgenerator. To avoid wasting space with full Poedit catalog, only put
translations actually needed by the plugin in there.
  • Loading branch information
vslavik committed Apr 11, 2024
1 parent 4ea0ba5 commit 9beb207
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 17 deletions.
23 changes: 22 additions & 1 deletion Poedit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@
B2CE6D171ACFCD95007E6863 /* Headers */,
B2CE6D181ACFCD95007E6863 /* Resources */,
B2CE6D291AD008F6007E6863 /* Set CFBundleVersion from git */,
B25CC3CE2BC8247900BED2FD /* Copy PO Translations */,
);
buildRules = (
);
Expand Down Expand Up @@ -1314,6 +1315,26 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
B25CC3CE2BC8247900BED2FD /* Copy PO Translations */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
dependencyFile = "$(DERIVED_FILES_DIR)/copy-translations.d";
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Copy PO Translations";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/copy-translations.done",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"${DEPS_BUILD_DIR}/gettext/bin:$PATH\"\necho \"${DERIVED_FILES_DIR}/copy-translations.done : \" \"${SRCROOT}\"/locales/*.po* \"${SRCROOT}/macos/copy-translations.sh\" >${DERIVED_FILES_DIR}/copy-translations.d\nmacos/copy-translations.sh quicklook \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\ntouch \"${DERIVED_FILE_DIR}/copy-translations.done\"\n";
};
B2C129D921C6CBAF004364B2 /* Ninja Build */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down Expand Up @@ -1404,7 +1425,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export MSGFMT=\"${DEPS_BUILD_DIR}/gettext/bin/msgfmt\"\necho \"${DERIVED_FILES_DIR}/copy-translations.done : \" \"${SRCROOT}\"/locales/*.po \"${SRCROOT}\"/deps/wx/locale/*.po >${DERIVED_FILES_DIR}/copy-translations.d\nmacos/copy-translations.sh \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\ntouch \"${DERIVED_FILE_DIR}/copy-translations.done\"\n";
shellScript = "export PATH=\"${DEPS_BUILD_DIR}/gettext/bin:$PATH\"\necho \"${DERIVED_FILES_DIR}/copy-translations.done : \" \"${SRCROOT}\"/locales/*.po* \"${SRCROOT}\"/deps/wx/locale/*.po \"${SRCROOT}/macos/copy-translations.sh\" >${DERIVED_FILES_DIR}/copy-translations.d\nmacos/copy-translations.sh app \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\ntouch \"${DERIVED_FILE_DIR}/copy-translations.done\"\n";
};
B2F287C6170DCF06004C1F41 /* Copy Gettext binaries, data files & translations */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
73 changes: 73 additions & 0 deletions locales/poedit-quicklook.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the Poedit package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Poedit 2.1\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-04-11 17:10+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: ../src/cloud_accounts_ui.cpp:433 ../src/export_html.cpp:77
msgid "Project:"
msgstr ""

#: ../src/cloud_accounts_ui.cpp:437 ../src/export_html.cpp:79
#: ../src/resources/prefs.xrc:11 ../src/resources/prefs.xrc:15
#: ../src/resources/properties.xrc:54
msgid "Language:"
msgstr ""

#: ../src/edframe.cpp:2628 ../src/export_html.cpp:103
#, c-format
msgid "Translated: %d of %d (%d %%)"
msgstr ""

#: ../src/edframe.cpp:2632 ../src/export_html.cpp:105
#, c-format
msgid "Remaining: %d"
msgstr ""

#: ../src/edframe.cpp:2642 ../src/export_html.cpp:117
#, c-format
msgid "%d entry"
msgid_plural "%d entries"
msgstr[0] ""
msgstr[1] ""

#: ../src/editing_area.cpp:396 ../src/editing_area.cpp:705
#: ../src/edlistctrl.cpp:661 ../src/edlistctrl.cpp:715
#: ../src/export_html.cpp:143
msgid "Source text"
msgstr ""

#. TRANSLATORS: Refers to symbolic ID of source text, i.e. when something like "button.label" is used instead of English text
#: ../src/editing_area.cpp:703 ../src/edlistctrl.cpp:709
#: ../src/export_html.cpp:137
msgid "Source text ID"
msgstr ""

#: ../src/edlistctrl.cpp:666 ../src/edlistctrl.cpp:737
#: ../src/export_html.cpp:145
#, c-format
msgid "Translation — %s"
msgstr ""

#: ../src/edlistctrl.cpp:714 ../src/export_html.cpp:142
#, c-format
msgid "Source text — %s"
msgstr ""

#: ../src/edlistctrl.cpp:736 ../src/export_html.cpp:146
msgid "unknown language"
msgstr ""
35 changes: 21 additions & 14 deletions macos/copy-translations.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash

set -e
set -Eeuo pipefail

DESTDIR="$1"

MSGFMT="${MSGFMT-msgfmt} -c"
SCOPE="$1"
DESTDIR="$2"

get_all_langs()
{
Expand All @@ -28,17 +27,21 @@ try_compile_po()
shortlang=${lang:0:2}
outfile="$2"
podir="$3"
reference_pot="$4"

if [ -f "$podir/$lang.po" ] ; then
if [ '!' "$outfile" -nt "$podir/$lang.po" ] ; then
echo "Compiling $podir/$lang.po"
$MSGFMT -o "$outfile" "$podir/$lang.po"
fi
infile="$podir/$lang.po"
elif [ -f "$podir/$shortlang.po" ] ; then
if [ '!' "$outfile" -nt "$podir/$shortlang.po" ] ; then
echo "Compiling $podir/$shortlang.po"
$MSGFMT -o "$outfile" "$podir/$shortlang.po"
fi
infile="$podir/$shortlang.po"
fi
[ -n "$infile" ] || exit 1

echo "compiling $podir/$lang.po"

if [ -n "$reference_pot" ] ; then
msgmerge -o- "$infile" "$reference_pot" | msgfmt -o "$outfile" -
else
msgfmt -o "$outfile" "$infile"
fi
}

Expand All @@ -47,8 +50,12 @@ for lang in `get_all_langs`; do

mkdir -p "$lproj"

try_compile_po $lang "$lproj/poedit.mo" locales
try_compile_po $lang "$lproj/wxstd.mo" deps/wx/locale
if [ $SCOPE = "app" ]; then
try_compile_po $lang "$lproj/poedit.mo" locales
try_compile_po $lang "$lproj/wxstd.mo" deps/wx/locale
else
try_compile_po $lang "$lproj/poedit-$SCOPE.mo" locales "locales/poedit-$SCOPE.pot"
fi
done

# macOS uses pt.lproj for pt-BR localization; bizarre as it is, we must do the
Expand Down
2 changes: 2 additions & 0 deletions scripts/refresh-pot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ find ../src -name "*.cpp" | sort | xargs xgettext ${XGETTEXT_ARGS} -
find ../src -name "*.h" | sort | xargs xgettext ${XGETTEXT_ARGS} -j -o _poedit.pot
${WXRC} --gettext ../src/resources/*.xrc | xgettext ${XGETTEXT_ARGS} -j -o _poedit.pot -

msggrep -N ../src/export_html.cpp _poedit.pot -o poedit-quicklook.pot

# -F is incompatible with --no-location, results in weird order, so remove location info
# in a secondary pass:
msgcat --no-location -o poedit.pot _poedit.pot
Expand Down
4 changes: 2 additions & 2 deletions src/quicklook/GeneratePreviewForURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void Initialize_plugin(void)

wxTranslations *trans = new wxTranslations();
wxTranslations::Set(trans);
trans->AddCatalog("poedit");
trans->AddCatalog("poedit-quicklook");

wxString bestTrans = trans->GetBestTranslation("poedit");
wxString bestTrans = trans->GetBestTranslation("poedit-quicklook");
Language uiLang = Language::TryParse(bestTrans.ToStdWstring());
uloc_setDefault(uiLang.IcuLocaleName().c_str(), &err);
}
Expand Down

0 comments on commit 9beb207

Please sign in to comment.