// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
namespace RuntimeForStatic {
//==================================================================================================

LANGID $Locale::GetLanguageId() $thread_static
{
   return GetLanguageId( false );
}
LANGID $Locale::GetLanguageId(bool ignoreCurrentThreadSettings) $thread_static
{
   if ( $RT::IsInitialized( true ) )
      if ( ignoreCurrentThreadSettings )
      {
         LANGID rtLanguageId = $RT::ThreadSettingsPattern($$).LanguageId;
         if ( rtLanguageId ) return rtLanguageId;
      }
      else
         if ( $Thread::IsInitialized() )
         {
            LANGID threadLanguageId = $Thread::LanguageId();
            if ( threadLanguageId ) return threadLanguageId;
         }
   return EnvironmentLanguageId();
}

LCID $Locale::GetLocaleId() $thread_static
{
   return GetLocaleId( false );
}
LCID $Locale::GetLocaleId(bool ignoreCurrentThreadSettings) $thread_static
{
   if ( $RT::IsInitialized( true ) )
      if ( ignoreCurrentThreadSettings )
      {
         LCID rtLocaleId = $RT::ThreadSettingsPattern($$).LocaleId;
         if ( rtLocaleId ) return rtLocaleId;
      }
      else
         if ( $Thread::IsInitialized() )
         {
            LCID threadLocaleId = $Thread::LocaleId();
            if (threadLocaleId) return threadLocaleId;
         }
   return EnvironmentLocaleId();
}

LANGID $Locale::EnvironmentLanguageId()
{
   return ::GetUserDefaultUILanguage();
   //return ::GetUserDefaultLangID();
}
LCID $Locale::EnvironmentLocaleId()
{
   return ::GetUserDefaultLCID();
}

//--------------------------------------------------------------------------------------------------

PCWSTR $Locale::GetText($A,PCWSTR defaultLangText,PCWSTR langText_1) $thread_static $not_null
{
   return GetText($ci, false, defaultLangText, langText_1 );
}
PCWSTR $Locale::GetText($A, bool ignoreCurrentThreadSettings,
                            PCWSTR defaultLangText, PCWSTR langText_1 ) $thread_static $not_null
{
   return GetTextExplicit($ci, PRIMARYLANGID( GetLanguageId( ignoreCurrentThreadSettings )),
                               defaultLangText, langText_1 );
}
PCWSTR $Locale::GetTextEx($A, LANGID languageId $optional,
                              PCWSTR defaultLangText, PCWSTR langText_1 ) $not_null
{
   return GetTextExplicit($ci, $_(languageId,GetLanguageId()), defaultLangText, langText_1 );
}

//--------------------------------------------------------------------------------------------------

PCWSTR $Locale::GetTextExplicit($A, LANGID languageId,
                                    PCWSTR defaultLangText, PCWSTR langText_1 ) $not_null
{
   $$VERIFY_POINTER_ARG( defaultLangText );
   $$VERIFY_POINTER_ARG( langText_1 );
   PCWSTR rslt = nullptr;
   switch ( PRIMARYLANGID( languageId ) )
   {
   case LANG_RUSSIAN:
      rslt = langText_1;
      break;
   default:
      rslt = defaultLangText;
   }
   return $checking::VerifyPointer($$, rslt );
}

//==================================================================================================
} // RuntimeForStatic
