Kaydet (Commit) ef291d99 authored tarafından Eike Rathke's avatar Eike Rathke

rsc with language tags

Change-Id: I5401a9bcbd1e359ef62e8d667edf6ead1479ce46
üst 8d470713
......@@ -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
for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
{
aLangFallbacks.push_back(getLangIdAndShortenLocale( this, aLg, aCountry, aVariant ) );
} while( !aLg.isEmpty() );
if( bAppendEnUsFallback )
rtl::OString aLang( OUStringToOString( *it, RTL_TEXTENCODING_ASCII_US));
sal_uInt32 nID = GetLangId( aLang );
bool bAdd = (nID == 0);
if ( bAdd )
{
aLg = "en";
aCountry = "US";
aVariant = rtl::OString();
aLangFallbacks.push_back( getLangIdAndShortenLocale( this, aLg, aCountry, aVariant ) );
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
......
......@@ -86,46 +86,33 @@ void RscLangEnum::Init( RscNameTable& rNames )
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() );
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment