diff options
Diffstat (limited to 'i18nlangtag')
-rw-r--r-- | i18nlangtag/Executable_localestr.mk | 29 | ||||
-rw-r--r-- | i18nlangtag/Module_i18nlangtag.mk | 1 | ||||
-rw-r--r-- | i18nlangtag/source/languagetag/languagetag.cxx | 32 | ||||
-rw-r--r-- | i18nlangtag/source/localestr/localestr.cxx | 20 |
4 files changed, 76 insertions, 6 deletions
diff --git a/i18nlangtag/Executable_localestr.mk b/i18nlangtag/Executable_localestr.mk new file mode 100644 index 000000000000..99195ffc7b80 --- /dev/null +++ b/i18nlangtag/Executable_localestr.mk @@ -0,0 +1,29 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Executable_Executable,localestr)) + +$(eval $(call gb_Executable_use_api,localestr,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_Executable_use_external,localestr,liblangtag)) + +$(eval $(call gb_Executable_use_libraries,localestr,\ + i18nlangtag \ + sal \ +)) + +$(eval $(call gb_Executable_add_exception_objects,localestr,\ + i18nlangtag/source/localestr/localestr \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/i18nlangtag/Module_i18nlangtag.mk b/i18nlangtag/Module_i18nlangtag.mk index edd2e1d2e2a9..0aecbc05ffdb 100644 --- a/i18nlangtag/Module_i18nlangtag.mk +++ b/i18nlangtag/Module_i18nlangtag.mk @@ -10,6 +10,7 @@ $(eval $(call gb_Module_Module,i18nlangtag)) $(eval $(call gb_Module_add_targets,i18nlangtag,\ Library_i18nlangtag \ + Executable_localestr \ )) $(eval $(call gb_Module_add_check_targets,i18nlangtag,\ diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index 4bf244284289..2da3b95174ed 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -279,6 +279,7 @@ private: OUString getRegion() const; OUString const & getVariants() const; bool hasScript() const; + OUString getGlibcLocaleString() const; void setScriptType(LanguageTag::ScriptType st); LanguageTag::ScriptType getScriptType() const; @@ -1920,6 +1921,25 @@ OUString LanguageTag::getVariants() const return aRet; } +OUString LanguageTagImpl::getGlibcLocaleString() const +{ + OUString sLocale; + if (!mpImplLangtag) + { + meIsLiblangtagNeeded = DECISION_YES; + const_cast<LanguageTagImpl*>(this)->synCanonicalize(); + } + if (mpImplLangtag) + { + char* pLang = lt_tag_convert_to_locale(mpImplLangtag, nullptr); + if (pLang) + { + sLocale = OUString::createFromAscii( pLang); + free(pLang); + } + } + return sLocale; +} OUString LanguageTag::getGlibcLocaleString( const OUString & rEncoding ) const { @@ -1934,16 +1954,16 @@ OUString LanguageTag::getGlibcLocaleString( const OUString & rEncoding ) const } else { - /* FIXME: use the aImplIsoLangGLIBCModifiersEntries table from - * i18nlangtag/source/isolang/isolang.cxx or let liblangtag handle it. - * So far no code was prepared for anything else than a simple - * language_country locale so we don't lose anything here right now. - * */ + aRet = getImpl()->getGlibcLocaleString(); + sal_Int32 nAt = aRet.indexOf('@'); + if (nAt != -1) + aRet = aRet.copy(0, nAt) + rEncoding + aRet.copy(nAt); + else + aRet += rEncoding; } return aRet; } - bool LanguageTagImpl::hasScript() const { if (!mbCachedScript) diff --git a/i18nlangtag/source/localestr/localestr.cxx b/i18nlangtag/source/localestr/localestr.cxx new file mode 100644 index 000000000000..c18531330c51 --- /dev/null +++ b/i18nlangtag/source/localestr/localestr.cxx @@ -0,0 +1,20 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include <i18nlangtag/languagetag.hxx> +#include <stdio.h> + +int main(int /*argc*/, char **argv) +{ + LanguageTag aTag(OUString::createFromAscii(argv[1])); + OUString aLocaleStr = aTag.getGlibcLocaleString(""); + printf("%s", aLocaleStr.toUtf8().getStr()); + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |