L10N.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 #include <BeSQLite/BeSQLite.h>
11 
12 // This macro defines a struct called STRUCT_NAME that has entries for a group of transatable strings.
13 // The struct has a GetString function that calls L10N::GetString using the specified NAMESPACE_NAME.
14 // The struct also has a GetNameSpace function that returns NAMESPACE_NAME as a constant string.
15 // The CHeaderToXLiff.py program recognizes this macro and knows how to extract messages from the entries.
16 // that follow it.
17 #define BENTLEY_TRANSLATABLE_STRINGS_START(STRUCT_NAME,NAMESPACE_NAME)\
18  struct STRUCT_NAME\
19  {\
20  typedef BeSQLite::L10N::NameSpace NameSpace;\
21  typedef BeSQLite::L10N::StringId StringId;\
22  static NameSpace GetNameSpace() {return NameSpace(#NAMESPACE_NAME);}\
23  static Utf8String GetString(StringId id) {return BeSQLite::L10N::GetString(GetNameSpace(), id);}\
24  static WString GetStringW(StringId id) {return WString(GetString(id).c_str(), BentleyCharEncoding::Utf8);}\
25 
26 // This macro is used to designate a transatable string inside a BENTLEY_TRANSLATABLE_STRINGS_START/BENTLEY_TRANSLATABLE_STRINGS_END block.
27 // It creates a static method named with the macro argument that returns a StringId with a stringized version of the same macro argument.
28 // This macro should always be followed on the same line with comment containing the english version of the string between ==" "== (e.g. // =="this is a prompt"===)
29 #define L10N_STRING(ID) static StringId ID() {return StringId(#ID);}
30 
31 // Indicates the end of a translatable string struct
32 #define BENTLEY_TRANSLATABLE_STRINGS_END };
33 
35 
36 //=======================================================================================
47 //=======================================================================================
48 struct L10N
49 {
51  struct NameSpace
52  {
54  explicit NameSpace(Utf8CP nameSpace=nullptr) : m_namespace(nameSpace) {}
55  bool operator ==(NameSpace const& other) const {return IsValid() && other.IsValid() && (m_namespace==other.m_namespace || 0==::strcmp(m_namespace, other.m_namespace));}
56  bool operator !=(NameSpace const& other) const {return !(*this == other);}
57  operator Utf8CP() const {return m_namespace;}
58  bool IsValid() const {return nullptr != m_namespace;}
59  };
61  struct StringId
62  {
64  explicit StringId(Utf8CP str=nullptr) : m_str(str) {}
65  operator Utf8CP() const {return m_str;}
66  bool operator ==(StringId const& other) const {return IsValid() && other.IsValid() && (m_str==other.m_str || 0==::strcmp(m_str, other.m_str));}
67  bool operator !=(StringId const& other) const {return !(*this == other);}
68  bool IsValid() const {return nullptr!=m_str;}
69  };
70 
73  struct SqlangFiles
74  {
75  BeFileName m_default;
76  BeFileName m_cultureNeutral;
77  BeFileName m_cultureSpecific;
78 
87  SqlangFiles(BeFileName defaultSqlangFile, BeFileName cultureNeutral=BeFileName(NULL), BeFileName cultureSpecific=BeFileName(NULL)) :
88  m_default(defaultSqlangFile), m_cultureNeutral(cultureNeutral), m_cultureSpecific(cultureSpecific) {}
89  };
90 
95  BE_SQLITE_EXPORT static BentleyStatus Initialize(SqlangFiles const& files);
96 
99  BE_SQLITE_EXPORT static void Suspend();
100 
103  BE_SQLITE_EXPORT static void Resume();
104 
106  BE_SQLITE_EXPORT static void Shutdown();
108 
115  BE_SQLITE_EXPORT static Utf8String GetString(NameSpace nameSpace, StringId id, bool* hasString=NULL);
116 
118  static bool HasString(NameSpace nameSpace, StringId id) {bool hasString; GetString(nameSpace, id, &hasString); return hasString;}
120 };
121 
122 // get rid of Bentley.h defintion.
123 #undef DECLARE_KEY_METHOD
124 
125 #define DEFINE_KEY_METHOD(CLS) void CLS::DummyKeyMethod() const {;}
126 #define DECLARE_KEY_METHOD __declspec(dllexport) virtual void DummyKeyMethod() const;
127 
bool operator!=(NameSpace const &other) const
Definition: L10N.h:56
bool IsValid() const
Definition: L10N.h:68
#define END_BENTLEY_SQLITE_NAMESPACE
Definition: BeSQLite.h:139
The identifier for a localized string, unique within a NameSpace.
Definition: L10N.h:61
static BE_SQLITE_EXPORT void Suspend()
The Suspend and Resume calls can be used to close and re-open the database files that store the trans...
static BE_SQLITE_EXPORT void Resume()
The Suspend and Resume calls can be used to close and re-open the database files that store the trans...
StringId(Utf8CP str=nullptr)
Definition: L10N.h:64
#define NULL
Definition: Bentley.h:157
L10N (chic numeronym for "localization") is used to obtain localized strings from one of 3 SQLang dat...
Definition: L10N.h:48
bool operator==(StringId const &other) const
Definition: L10N.h:66
Utf8CP m_namespace
Definition: L10N.h:53
BentleyStatus
Definition: Bentley.h:208
Set of 1 to 3 SQLang database files.
Definition: L10N.h:73
bool IsValid() const
Definition: L10N.h:58
NameSpace(Utf8CP nameSpace=nullptr)
Definition: L10N.h:54
#define BEGIN_BENTLEY_SQLITE_NAMESPACE
Definition: BeSQLite.h:138
#define BE_SQLITE_EXPORT
Definition: BeSQLite.h:124
BeFileName m_cultureSpecific
Definition: L10N.h:77
A globally unique identifier for a group of localized strings.
Definition: L10N.h:51
Utf8Char const * Utf8CP
Definition: Bentley.h:229
BeFileName m_cultureNeutral
Definition: L10N.h:76
SqlangFiles(BeFileName defaultSqlangFile, BeFileName cultureNeutral=BeFileName(NULL), BeFileName cultureSpecific=BeFileName(NULL))
Definition: L10N.h:87
bool operator==(NameSpace const &other) const
Definition: L10N.h:55
BeFileName m_default
Definition: L10N.h:75
bool operator!=(StringId const &other) const
Definition: L10N.h:67
Utf8CP m_str
Definition: L10N.h:63

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.