diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-10-05 15:48:01 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-10-09 09:52:33 +0200 |
commit | 283229f5bc27ce23456b9cbd9aff75ff44707105 (patch) | |
tree | ecadd85a8937555c8404290ac19c0af6baf4f266 | |
parent | cc6d591e1c4202afdbc30a76fd56d66b7547fa34 (diff) |
Related: tdf#83128 support translation of plural forms
Change-Id: Id3d41099a895ca5423be2ac3d497851bc65eaff7
Reviewed-on: https://gerrit.libreoffice.org/61426
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/unotools/resmgr.hxx | 1 | ||||
-rw-r--r-- | sc/inc/scresid.hxx | 1 | ||||
-rw-r--r-- | sc/inc/strings.hrc | 3 | ||||
-rw-r--r-- | sc/source/ui/app/scdll.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/dialogs/searchresults.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/inc/searchresults.hxx | 1 | ||||
-rwxr-xr-x | solenv/bin/hrcex | 2 | ||||
-rw-r--r-- | unotools/source/i18n/resmgr.cxx | 26 |
8 files changed, 38 insertions, 5 deletions
diff --git a/include/unotools/resmgr.hxx b/include/unotools/resmgr.hxx index 65e730bd0021..8da6aefac60c 100644 --- a/include/unotools/resmgr.hxx +++ b/include/unotools/resmgr.hxx @@ -29,6 +29,7 @@ namespace Translate { UNOTOOLS_DLLPUBLIC std::locale Create(const sal_Char* pPrefixName, const LanguageTag& rLocale = SvtSysLocale().GetUILanguageTag()); UNOTOOLS_DLLPUBLIC OUString get(const char* pId, const std::locale &loc); + UNOTOOLS_DLLPUBLIC OUString nget(const char* pId, int n, const std::locale &loc); UNOTOOLS_DLLPUBLIC void SetReadStringHook( ResHookProc pProc ); UNOTOOLS_DLLPUBLIC ResHookProc GetReadStringHook(); UNOTOOLS_DLLPUBLIC OUString ExpandVariables(const OUString& rString); diff --git a/sc/inc/scresid.hxx b/sc/inc/scresid.hxx index e7bdb167ca5d..5a63bd809fb5 100644 --- a/sc/inc/scresid.hxx +++ b/sc/inc/scresid.hxx @@ -24,6 +24,7 @@ #include "scdllapi.h" OUString SC_DLLPUBLIC ScResId(const char* pId); +OUString SC_DLLPUBLIC ScResId(const char* pId, int nCardinality); #endif // SC_SCRESMGR_HXX diff --git a/sc/inc/strings.hrc b/sc/inc/strings.hrc index 17916a1ab5ba..dc606e3bd379 100644 --- a/sc/inc/strings.hrc +++ b/sc/inc/strings.hrc @@ -21,6 +21,7 @@ #define INCLUDED_SC_INC_STRINGS_HRC #define NC_(Context, String) (Context "\004" u8##String) +#define NNC_(Context, StringSingular, StringPlural) (Context "\004" u8##StringSingular "\004" u8##StringPlural) // Strings for interface names ------------------------------------------- @@ -49,7 +50,7 @@ #define SCSTR_RENAMEOBJECT NC_("SCSTR_RENAMEOBJECT", "Name Object") #define STR_INSERTGRAPHIC NC_("STR_INSERTGRAPHIC", "Insert Image") #define STR_QUERYROTATION NC_("STR_QUERYROTATION", "This image is rotated. Would you like to rotate it into standard orientation?") -#define SCSTR_TOTAL NC_("SCSTR_TOTAL", "%1 results found") +#define SCSTR_TOTAL NNC_("SCSTR_TOTAL", "1 result found", "%1 results found") #define SCSTR_SKIPPED NC_("SCSTR_SKIPPED", "(only %1 are listed)") // Attribute #define SCSTR_PROTECTDOC NC_("SCSTR_PROTECTDOC", "Protect Spreadsheet Structure") diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx index 406a0eac4c34..435cb6fa1549 100644 --- a/sc/source/ui/app/scdll.cxx +++ b/sc/source/ui/app/scdll.cxx @@ -113,6 +113,11 @@ OUString ScResId(const char* pId) return Translate::get(pId, SC_MOD()->GetResLocale()); } +OUString ScResId(const char* pId, int nCardinality) +{ + return Translate::nget(pId, nCardinality, SC_MOD()->GetResLocale()); +} + void ScDLL::Init() { if ( SfxApplication::GetModule(SfxToolsModule::Calc) ) // Module already active diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx index 38facd11121b..436e0ec0ab99 100644 --- a/sc/source/ui/dialogs/searchresults.cxx +++ b/sc/source/ui/dialogs/searchresults.cxx @@ -26,7 +26,6 @@ namespace sc { SearchResultsDlg::SearchResultsDlg( SfxBindings* _pBindings, vcl::Window* pParent ) : ModelessDialog(pParent, "SearchResultsDialog", "modules/scalc/ui/searchresults.ui"), aSkipped( ScResId( SCSTR_SKIPPED ) ), - aTotal( ScResId( SCSTR_TOTAL ) ), mpBindings(_pBindings), mpDoc(nullptr) { get(mpSearchResults, "lbSearchResults"); @@ -148,7 +147,8 @@ void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatche } } - OUString aSearchResults = ScGlobal::ReplaceOrAppend( aTotal, "%1", OUString::number( aList.mnCount ) ); + OUString aTotal(ScResId(SCSTR_TOTAL, aList.mnCount)); + OUString aSearchResults = aTotal.replaceFirst("%1", OUString::number(aList.mnCount)); if (aList.mnCount > ListWrapper::mnMaximum) aSearchResults += " " + ScGlobal::ReplaceOrAppend( aSkipped, "%1", OUString::number( ListWrapper::mnMaximum ) ); mpSearchResults->SetText(aSearchResults); diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx index f07cc19ce5df..c50a12225727 100644 --- a/sc/source/ui/inc/searchresults.hxx +++ b/sc/source/ui/inc/searchresults.hxx @@ -25,7 +25,6 @@ class SearchResultsDlg : public ModelessDialog VclPtr<SvSimpleTable> mpList; VclPtr<FixedText> mpSearchResults; OUString aSkipped; - OUString aTotal; SfxBindings* mpBindings; ScDocument* mpDoc; diff --git a/solenv/bin/hrcex b/solenv/bin/hrcex index 5d5fffd486d6..9d3a2788d4ba 100755 --- a/solenv/bin/hrcex +++ b/solenv/bin/hrcex @@ -22,7 +22,7 @@ for o, a in myopts: ofile = a with open(ofile, "a") as output: - input = check_output(["xgettext", "-C", "--add-comments", "--keyword=NC_:1c,2", "--from-code=UTF-8", "--no-wrap", ifile, "-o", "-"]) + input = check_output(["xgettext", "-C", "--add-comments", "--keyword=NC_:1c,2", "--keyword=NNC_:1c,2,3", "--from-code=UTF-8", "--no-wrap", ifile, "-o", "-"]) po = polib.pofile(input) if len(po) != 0: print >> output, "" diff --git a/unotools/source/i18n/resmgr.cxx b/unotools/source/i18n/resmgr.cxx index f93aaa00b226..8d4fcb5eac33 100644 --- a/unotools/source/i18n/resmgr.cxx +++ b/unotools/source/i18n/resmgr.cxx @@ -206,6 +206,7 @@ namespace Translate { sContext = OString(pContextAndId, pId - pContextAndId); ++pId; + assert(!strchr(pId, '\004') && "should be using nget, not get"); } //if it's a key id locale, generate it here @@ -220,6 +221,31 @@ namespace Translate return ExpandVariables(createFromUtf8(ret.data(), ret.size())); } + OUString nget(const char* pContextAndIds, int n, const std::locale &loc) + { + OString sContextIdId(pContextAndIds); + std::vector<OString> aContextIdId; + sal_Int32 nIndex = 0; + do + { + aContextIdId.push_back(sContextIdId.getToken(0, '\004', nIndex)); + } + while (nIndex >= 0); + assert(aContextIdId.size() == 3 && "should be using get, not nget"); + + //if it's a key id locale, generate it here + if (std::use_facet<boost::locale::info>(loc).language() == "qtz") + { + OString sKeyId(genKeyId(aContextIdId[0] + "|" + aContextIdId[1])); + int nForm = n == 0 ? 1 : 2; + return OUString::fromUtf8(sKeyId) + OUStringLiteral1(0x2016) + createFromUtf8(aContextIdId[nForm].getStr(), aContextIdId[nForm].getLength()); + } + + //otherwise translate it + const std::string ret = boost::locale::npgettext(aContextIdId[0].getStr(), aContextIdId[1].getStr(), aContextIdId[2].getStr(), n, loc); + return ExpandVariables(createFromUtf8(ret.data(), ret.size())); + } + static ResHookProc pImplResHookProc = nullptr; OUString ExpandVariables(const OUString& rString) |