summaryrefslogtreecommitdiff
path: root/rsc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-04-03 20:59:40 +0200
committerEike Rathke <erack@redhat.com>2013-04-03 21:19:24 +0200
commitef291d99fb706675607acdc80f1fd05e952f0a34 (patch)
tree3a234b360a71a9b98ccc4b616bf7b739eb7dd831 /rsc
parent8d470713b6187e6284077a7b951335ecacd8befa (diff)
rsc with language tags
Change-Id: I5401a9bcbd1e359ef62e8d667edf6ead1479ce46
Diffstat (limited to 'rsc')
-rw-r--r--rsc/source/parser/rscdb.cxx79
-rw-r--r--rsc/source/parser/rscibas.cxx63
2 files changed, 50 insertions, 92 deletions
diff --git a/rsc/source/parser/rscdb.cxx b/rsc/source/parser/rscdb.cxx
index 0b70e09fa934..38c5a1913109 100644
--- a/rsc/source/parser/rscdb.cxx
+++ b/rsc/source/parser/rscdb.cxx
@@ -23,6 +23,7 @@
#include <string.h>
#include <tools/rc.h>
+#include <i18npool/languagetag.hxx>
#include <rtl/strbuf.hxx>
#include <sal/log.hxx>
#include <sal/macros.h>
@@ -74,76 +75,42 @@ RscTypCont :: RscTypCont( RscError * pErrHdl,
Init();
}
-static sal_uInt32 getLangIdAndShortenLocale( RscTypCont* pTypCont,
- rtl::OString& rLang,
- rtl::OString& rCountry,
- rtl::OString& rVariant )
-{
- rtl::OStringBuffer aLangStr( 64 );
- aLangStr.append( rLang.toAsciiLowerCase() );
- if( !rCountry.isEmpty() )
- {
- aLangStr.append( '-' );
- aLangStr.append( rCountry.toAsciiUpperCase() );
- }
- if( !rVariant.isEmpty() )
- {
- aLangStr.append( '-' );
- aLangStr.append( rVariant );
- }
- rtl::OString aL( aLangStr.makeStringAndClear() );
- sal_uInt32 nRet = GetLangId( aL );
- if( nRet == 0 )
- {
- pTypCont->AddLanguage( aL.getStr() );
- nRet = GetLangId( aL );
- }
- if( !rVariant.isEmpty() )
- rVariant = rtl::OString();
- else if( !rCountry.isEmpty() )
- rCountry = rtl::OString();
- else
- rLang = rtl::OString();
-#if OSL_DEBUG_LEVEL > 1
- fprintf( stderr, " %s (0x%hx)", aL.getStr(), (int)nRet );
-#endif
- return nRet;
-}
-
rtl::OString RscTypCont::ChangeLanguage(const rtl::OString& rNewLang)
{
rtl::OString aRet = aLanguage;
aLanguage = rNewLang;
- rtl::OString aLang = aLanguage;
- rtl::OString aLg, aCountry, aVariant;
- sal_Int32 nIndex = 0;
- aLg = aLang.getToken( 0, '-', nIndex );
- if( nIndex != -1 )
- aCountry = aLang.getToken( 0, '-', nIndex );
- if( nIndex != -1 )
- aVariant = aLang.copy( nIndex );
-
+ ::std::vector< OUString > aFallbacks;
+ if (rNewLang.isEmpty())
+ aFallbacks.push_back( "" ); // do not resolve to SYSTEM (en-US)
+ else
+ aFallbacks = LanguageTag( OStringToOUString( rNewLang, RTL_TEXTENCODING_ASCII_US)).getFallbackStrings();
bool bAppendEnUsFallback =
! (rNewLang.equalsIgnoreAsciiCase( "en-US" ) ||
rNewLang.equalsIgnoreAsciiCase( "x-no-translate" ) );
+ if (bAppendEnUsFallback)
+ aFallbacks.push_back( "en-US");
#if OSL_DEBUG_LEVEL > 1
- fprintf( stderr, "RscTypCont::ChangeLanguage:" );
+ fprintf( stderr, "RscTypCont::ChangeLanguage: " );
#endif
- aLangFallbacks.clear();
- do
- {
- aLangFallbacks.push_back(getLangIdAndShortenLocale( this, aLg, aCountry, aVariant ) );
- } while( !aLg.isEmpty() );
+ aLangFallbacks.clear();
- if( bAppendEnUsFallback )
+ for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
{
- aLg = "en";
- aCountry = "US";
- aVariant = rtl::OString();
- aLangFallbacks.push_back( getLangIdAndShortenLocale( this, aLg, aCountry, aVariant ) );
+ rtl::OString aLang( OUStringToOString( *it, RTL_TEXTENCODING_ASCII_US));
+ sal_uInt32 nID = GetLangId( aLang );
+ bool bAdd = (nID == 0);
+ if ( bAdd )
+ {
+ AddLanguage( aLang.getStr() );
+ nID = GetLangId( aLang );
+ }
+#if OSL_DEBUG_LEVEL > 1
+ fprintf( stderr, " '%s' (0x%hx) (%s)", aLang.getStr(), (int)nID, (bAdd ? "added" : "exists") );
+#endif
+ aLangFallbacks.push_back( nID);
}
#if OSL_DEBUG_LEVEL > 1
diff --git a/rsc/source/parser/rscibas.cxx b/rsc/source/parser/rscibas.cxx
index 194c9740f80c..9b74545534b2 100644
--- a/rsc/source/parser/rscibas.cxx
+++ b/rsc/source/parser/rscibas.cxx
@@ -84,48 +84,35 @@ void RscLangEnum::Init( RscNameTable& rNames )
{
#if OSL_DEBUG_LEVEL > 2
fprintf( stderr, "ISO Language in : %d, 0x%04x, %s\n",
- (int)nIndex,
- (unsigned)pLangEntry->mnLang,
- OUStringToOString( LanguageTag( pLangEntry->mnLang ).getBcp47(), RTL_TEXTENCODING_ASCII_US).getStr() );
+ (int)nIndex,
+ (unsigned)pLangEntry->mnLang,
+ OUStringToOString( pLangEntry->getTagString(), RTL_TEXTENCODING_ASCII_US).getStr());
+ fprintf( stderr, "ISO Language out:");
#endif
- rtl::OString aLang(pLangEntry->maLangStr, strlen(pLangEntry->maLangStr));
- rtl::OString aCountry(pLangEntry->maCountry, strlen(pLangEntry->maCountry));
- if ( aCountry.isEmpty() || aLang.equalsIgnoreAsciiCase(aCountry) )
+ LanguageTag aLanguageTag( pLangEntry->getTagString());
+ ::std::vector< OUString > aFallbacks( aLanguageTag.getFallbackStrings());
+ for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
{
+ OString aLang( OUStringToOString( *it, RTL_TEXTENCODING_ASCII_US));
SetConstant( rNames.Put( aLang.getStr(), CONSTNAME, mnLangId ), mnLangId );
- if ( ! GetLangId( aLang ))
+ bool bAdd = (GetLangId( aLang ) == 0);
+ if ( bAdd )
ULong_Iso_map[ aLang ] = mnLangId;
#if OSL_DEBUG_LEVEL > 2
- fprintf( stderr, "ISO Language out: %s 0x%lx\n", aLang.getStr(), mnLangId );
+ fprintf( stderr, " %s 0x%lx (%s)", aLang.getStr(), mnLangId, (bAdd ? "added" : "exists") );
#endif
mnLangId++;
}
- else
- {
- SetConstant( rNames.Put( aLang.getStr(), CONSTNAME, mnLangId ), mnLangId );
- if ( ! GetLangId( aLang ))
- ULong_Iso_map[ aLang ] = mnLangId;
-#if OSL_DEBUG_LEVEL > 2
- fprintf( stderr, "ISO Language out: %s 0x%lx", aLang.getStr(), mnLangId );
-#endif
- mnLangId++;
- aLang = aLang + rtl::OString( '-' ) + aCountry.toAsciiUpperCase();
- SetConstant( rNames.Put( aLang.getStr(), CONSTNAME, mnLangId ), mnLangId );
- if ( ! GetLangId( aLang ))
- ULong_Iso_map[ aLang ] = mnLangId;
#if OSL_DEBUG_LEVEL > 2
- fprintf( stderr, " %s 0x%lx\n", aLang.getStr(), mnLangId );
+ fprintf( stderr, "\n");
#endif
- mnLangId++;
-// hack - survive "x-no-translate"
- if (aLang.equalsL(RTL_CONSTASCII_STRINGPARAM("en-US")))
- {
- SetConstant( rNames.Put( "x-comment", CONSTNAME, mnLangId ), mnLangId );
- mnLangId++;
- }
- }
nIndex++;
}
+ // hack - survive "x-no-translate"
+ /* XXX: that ^^^ was the original comment, but we're adding "x-comment"
+ * here? Which is good anyway. */
+ SetConstant( rNames.Put( "x-comment", CONSTNAME, mnLangId ), mnLangId );
+ mnLangId++;
rtl::OString aEnvIsoTokens = getenv( "RSC_LANG_ISO" );
if ( !aEnvIsoTokens.isEmpty() )
@@ -139,10 +126,12 @@ void RscLangEnum::Init( RscNameTable& rNames )
if ( !aIsoToken.isEmpty() )
{
SetConstant( rNames.Put( aIsoToken.getStr(), CONSTNAME, mnLangId ), mnLangId );
- if ( ! GetLangId( aIsoToken ))
+ bool bAdd = (GetLangId( aIsoToken ) == 0);
+ if ( bAdd )
ULong_Iso_map[ aIsoToken ] = mnLangId;
#if OSL_DEBUG_LEVEL > 2
- fprintf( stderr, "Env ISO Language out: %s 0x%lx\n", aIsoToken.getStr(), mnLangId );
+ fprintf( stderr, "Env ISO Language out: %s 0x%lx (%s)\n",
+ aIsoToken.getStr(), mnLangId, (bAdd ? "added" : "exists") );
#endif
mnLangId++;
}
@@ -166,20 +155,22 @@ void RscLangEnum::Init( RscNameTable& rNames )
Atom RscLangEnum::AddLanguage( const char* pLang, RscNameTable& rNames )
{
Atom nResult = 0;
+ bool bAdd = false;
KEY_STRUCT aStruct;
if( ! rNames.Get( nResult = pHS->getID( pLang ), &aStruct ) )
{
SetConstant( nResult = rNames.Put( pLang, CONSTNAME, mnLangId ), mnLangId );
// insert new lang to ULong_Iso_map
rtl::OString aLang( pLang );
- if ( ! GetLangId( aLang ))
+ bAdd = (GetLangId( aLang ) == 0);
+ if ( bAdd )
ULong_Iso_map[ aLang ] = mnLangId;
// increase id counter
mnLangId++;
}
- #if OSL_DEBUG_LEVEL > 2
- fprintf( stderr, "AddLanguage( %s ) = %d\n", pLang, nResult );
- #endif
+#if OSL_DEBUG_LEVEL > 2
+ fprintf( stderr, "AddLanguage( '%s' ) = %d (%s)\n", pLang, nResult, (bAdd ? "added" : "exists") );
+#endif
return nResult;
}