21#if defined(BI_MULTI_THREAD_RTL)
37static const tchar*
const null_string =
_T(
"");
44#define AUTOLANG_CACHEDNEUT 0x02
45#define AUTOLANG_CACHEDLOAD 0x01
49struct _TLocaleCacheBase;
55struct _TLocaleCacheList
56#if defined(BI_MULTI_THREAD_RTL)
60 _TLocaleCacheList() : Next(nullptr)
65 _TLocaleCache* Lookup(
const tchar* name);
66 void AddLink(_TLocaleCacheBase* next);
68 _TLocaleCacheBase* Next;
70#if defined(BI_MULTI_THREAD_RTL)
79static _TLocaleCacheList& GetLocaleCacheList()
81#if defined(BI_MULTI_THREAD_RTL)
82 static TTlsContainer<_TLocaleCacheList> localeCacheList;
83 return localeCacheList.Get();
85 static _TLocaleCacheList localeCacheList;
86 return localeCacheList;
95 _TLocaleCacheList& InitLocalCacheList = GetLocaleCacheList();
98#if defined(BI_MULTI_THREAD_RTL)
110static HINSTANCE GetLocaleResourceModule()
116 return ::GetModuleHandle(
nullptr);
125struct _TLocaleCacheBase {
127 const tchar* Neutral;
128 _TLocaleCacheBase* Next;
130 _TLocaleCacheBase(
const tchar* name,
long hash);
136struct _TLocaleCache :
public _TLocaleCacheBase {
137 void*
operator new(
size_t size,
int buflen);
138#if defined(BI_COMP_MSC)
139 void operator delete(
void* p,
int buflen);
141 _TLocaleCache(
const tchar* name,
long hash, HRSRC rscHdl, HGLOBAL resData);
143 const tchar* Translate(TLangId lang);
148 static _TLocaleCache* FromBuf(
const tchar* buf)
149 {
return reinterpret_cast<_TLocaleCache*
>(
const_cast<char*
>(
reinterpret_cast<const char*
>(buf)) - BufOffset);}
151 static ptrdiff_t BufOffset;
165_TLocaleCacheBase::_TLocaleCacheBase(
const tchar* name,
long hash)
171 GetLocaleCacheList().AddLink(
this);
174void* _TLocaleCache::operator
new(
size_t size,
int buflen)
176 return ::operator
new(size+buflen);
178ptrdiff_t _TLocaleCache::BufOffset = 0;
180#if defined(BI_COMP_MSC)
181void _TLocaleCache::operator
delete(
void* p, int)
183 ::operator
delete(p);
187_TLocaleCache::_TLocaleCache(
const tchar* name,
long hash,
188 HRSRC resHdl, HGLOBAL resData)
190 _TLocaleCacheBase(name, hash),
193 BufOffset =
reinterpret_cast<char*
>(Buf) -
reinterpret_cast<char*
>(
this);
195 *(HGLOBAL*)(Buf+1) = resData;
200_TLocaleCache* _TLocaleCacheList::Lookup(
const tchar* name)
203 const tchar* neut = name + 1;
205 const tchar* pc = name;
207 hash = hash*2 ^ *pc++;
208 for (_TLocaleCacheBase* entry = Next; entry; entry = entry->Next) {
209 if (hash == entry->Hash) {
210 const tchar* pc = entry->Neutral;
213 if (TLocaleString::CompareLang(pc,neut,TLocaleString::NativeLangId) != 0)
214 return pc == entry->Neutral ? (_TLocaleCache*)entry : nullptr;
220 const auto module = GetLocaleResourceModule();
223 new _TLocaleCacheBase(name, hash);
226 HGLOBAL resData = ::LoadResource(module, resHdl);
234 int maxLen =
static_cast<int>((
sizeof(HGLOBAL) +
sizeof(
tchar) - 1) /
sizeof(
tchar));
237 ::FreeResource(resData);
238 new _TLocaleCacheBase(name, hash);
247 while ((c=*pr++) >=
_T(
' ')) ;
248 if (
static_cast<int>(pr-p) > maxLen)
249 maxLen =
static_cast<int>(pr-p);
251 _TLocaleCache* cache =
new(maxLen *
static_cast<int>(
sizeof(
tchar)))_TLocaleCache(neut, hash, resHdl, resData);
258_TLocaleCache::Translate(TLangId reqLang)
261 if (ReqLangId == InvalidLangId) {
262 resData = *(HGLOBAL*)(Buf+1);
268 if (reqLang == ActLangId)
270 if (reqLang == ReqLangId) {
271 if (ActLangId != InvalidLangId)
278 if ((resData = ::LoadResource(GetLocaleResourceModule(), ResHdl)) ==
nullptr)
289 while ((c = *pr) != 0) {
291 actLang = resLang = TLocaleString::NativeLangId;
295 resLang =
TLangId(((c - 1)<<10) | *++pr);
298 if (resLang == reqLang) {
303 if ((tchar)resLang == (tchar)reqLang) {
304 if ((tchar)actLang != (tchar)reqLang || resLang == (reqLang & 0x00FF)) {
309 for ( ; *pr >=
_T(
' '); ++pr)
314 while (*translation <
_T(
' '))
316 if (actLang != ActLangId) {
318 for (pr = translation, pc = Buf + 1; *pr >=
_T(
' '); )
322 if (reqLang != ActLangId)
333 ::FreeResource(resData);
337_TLocaleCacheList::~_TLocaleCacheList()
341 _TLocaleCacheBase* p = Next;
347void _TLocaleCacheList::AddLink(_TLocaleCacheBase* link)
380 _TLocaleCache* cache;
389 if ((cache = GetLocaleCacheList().Lookup(
Private)) ==
nullptr)
392 return cache->Translate(reqLang);
396 if ((cache = GetLocaleCacheList().Lookup(
Private)) ==
nullptr)
399 return cache->Translate(reqLang);
403 cache = _TLocaleCache::FromBuf(
Private);
404 return cache->Translate(reqLang);
408TLocaleString::operator
const tchar*()
const
Definition of class TAppDictionary.
Definition of class TApplication.
TLocaleString - localized name support.
#define AUTOLANG_LOAD
indicates resource name to load (binary)
#define AUTOLANG_XLAT
indicates name to be localized (binary)
#define AUTOLANG_RCID
indicates name specified by numeric ID
#define AUTOLANG_CACHEDNEUT
#define AUTOLANG_CACHEDLOAD
Object Windows Library (OWLNext Core).
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
const TLangId InvalidLangId
const TLangId LangNeutral
const TLangId LangUserDefault
TAppDictionary & OWLGetAppDictionary()
Global exported TAppDictionary in Owl.
const TLangId LangSysDefault
General definitions used by all ObjectWindows programs.
Designed to provide support for localized registration parameters, the TLocaleString Struct defines a...
static TLangId NativeLangId
The base language ID of non-localized strings.
static TLangId SystemDefaultLangId
The default language identifier.
const tchar * Private
string pointer used for initialization
static int CompareLang(const tchar *s1, const tchar *s2, TLangId)
This function may be re-implemented with enhanced NLS support in another module.
static TLangId GetSystemLangId()
platform-dependent implementation
static TLangId UserDefaultLangId
The user-defined default language identifier.
static TLangId GetUserLangId()
platform-dependent implementation
int Compare(const tchar *str, TLangId lang)
insensitive compare
const tchar * Translate(TLangId lang)
translate string
static HINSTANCE Module
The handle of the file containing the resource.
static TLocaleString Null
reference a null string
static int IsNativeLangId(TLangId lang)
returns bool true if native