summaryrefslogtreecommitdiff
path: root/i18npool/source/nativenumber/nativenumbersupplier.cxx
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-06-07 14:26:42 +0200
committerEike Rathke <erack@redhat.com>2018-06-27 17:29:19 +0200
commitb435767f8953702bb5fe01edae3ad0abfbd2cacc (patch)
tree9c80662e4c3a096b0d48d2c0a26f56939ffaa7cc /i18npool/source/nativenumber/nativenumbersupplier.cxx
parentb491bb4b1e2eb6745ced3e958550ea8526cd2f2a (diff)
tdf#115007 add NatNum12 formatting to dates
to support variants of preposition, suffixation, article or their combinations. For example, Catalan "de març"/"d'abril", English "1st of May"/"First of May", Hungarian "május 1-je/május 2-a" (May 1/2) or Turkish "2018'de/2019'da" (in 2018/2019) usage can be automatic in templates and mail merge. When the date format contains more than a date keyword, it needs to specify in the NatNum12 argument which date element has got special formatting (described by libnumbertext formatting codes, and an optional initial capitalize/upper/title argument): '[NatNum12 ordinal-number]D' -> "1st" '[NatNum12 D=ordinal-number]D" of "MMMM' -> "1st of April" '[NatNum12 D=ordinal]D" of "MMMM' -> "first of April" '[NatNum12 YYYY=title year,D=capitalize ordinal] D"of "MMMM", "YYYY' -> "First of April, Nineteen Ninety" Note: set only for YYYY, MMMM, M, DDDD, D and NNN/AAAA in date formats. It's possible to extend this for other keywords and date + time combinations, according to the possible language requirements. Note 2: l10n date formats can use the new NatNum12 date formats from formatindex=60, see FormatElement in i18npool/source/localedata/ XML files and FormatElement specification: https://opengrok.libreoffice.org/xref/core/i18npool/source/localedata/data/locale.dtd#223 Change-Id: I598849f1492f4012e83cef9293773badbff16206 Reviewed-on: https://gerrit.libreoffice.org/55613 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: László Németh <nemeth@numbertext.org> Reviewed-on: https://gerrit.libreoffice.org/55767 Tested-by: Jenkins Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'i18npool/source/nativenumber/nativenumbersupplier.cxx')
-rw-r--r--i18npool/source/nativenumber/nativenumbersupplier.cxx14
1 files changed, 6 insertions, 8 deletions
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index 5fb34c993167..8c3698216b81 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -588,10 +588,8 @@ OUString getNumberText(const Locale& rLocale, const OUString& rNumberString,
break;
}
- if (count == 0)
- return rNumberString;
-
- OUString aNumberStr = sBuf.makeStringAndClear();
+ // Handle also month and day names for NatNum12 date formatting
+ const OUString& rNumberStr = (count == 0) ? rNumberString : sBuf.makeStringAndClear();
// Guard the static variables below.
osl::MutexGuard aGuard( theNatNumMutex::get());
@@ -606,17 +604,17 @@ OUString getNumberText(const Locale& rLocale, const OUString& rNumberString,
// of the continuous update of the multiple number names during typing.
// We fix this by buffering the result of the conversion.
static std::unordered_map<OUString, std::map<OUString, OUString>> aBuff;
- auto& rItems = aBuff[aNumberStr];
+ auto& rItems = aBuff[rNumberStr];
auto& rItem = rItems[numbertext_prefix + aLoc];
if (rItem.isEmpty())
{
- rItem = xNumberText->getNumberText(numbertext_prefix + aNumberStr, rLocale);
+ rItem = xNumberText->getNumberText(numbertext_prefix + rNumberStr, rLocale);
// use number at missing number to text conversion
if (rItem.isEmpty())
- rItem = aNumberStr;
+ rItem = rNumberStr;
}
OUString sResult = rItem;
- if (i < len)
+ if (i != 0 && i < len)
sResult += rNumberString.copy(i);
return sResult;
}