BibleTime
btlocalemgr.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btlocalemgr.h"
14 
15 #include <QByteArray>
16 #include "../../util/btassert.h"
17 
18 // Sword includes:
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wextra-semi"
21 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
22 #include <localemgr.h>
23 #pragma GCC diagnostic pop
24 
25 namespace {
26 
27 struct BtLocaleMgrImpl final: public sword::LocaleMgr {
28 
29  friend sword::LocaleMap const & ::BtLocaleMgr::internalSwordLocales();
30 
31 };
32 
34  auto * btLocaleMgr =
35  dynamic_cast<BtLocaleMgrImpl *>(
36  sword::LocaleMgr::getSystemLocaleMgr());
37  if (!btLocaleMgr) {
38  /* Beware that sword::StringMgr::setSystemStringMgr() also replaces the
39  Sword system locale manager with new sword::LocaleMgr(). */
40  btLocaleMgr = new BtLocaleMgrImpl();
41  sword::LocaleMgr::setSystemLocaleMgr(btLocaleMgr);
42  }
43  return *btLocaleMgr;
44 }
45 
46 } // anonymous namespace
47 
48 auto BtLocaleMgr::internalSwordLocales() -> sword::LocaleMap const & {
49  auto const & btLocaleMgr = btLocaleMgrInstance();
50  BT_ASSERT(btLocaleMgr.locales);
51  return *btLocaleMgr.locales;
52 }
53 
54 sword::SWLocale * BtLocaleMgr::localeTranslator()
55 { return btLocaleMgrInstance().getLocale("locales"); }
56 
58 { return btLocaleMgrInstance().getDefaultLocaleName(); }
59 
60 void BtLocaleMgr::setDefaultLocaleName(QString const & localeName) {
61  static_cast<sword::LocaleMgr &>(btLocaleMgrInstance()).setDefaultLocaleName(
62  localeName.toUtf8().constData());
63 }
#define BT_ASSERT(...)
Definition: btassert.h:17
QString defaultLocaleName()
Definition: btlocalemgr.cpp:57
sword::SWLocale * localeTranslator()
Definition: btlocalemgr.cpp:54
std::map< sword::SWBuf, sword::SWLocale * > const & internalSwordLocales()
Definition: btlocalemgr.cpp:48
void setDefaultLocaleName(QString const &localeName)
Definition: btlocalemgr.cpp:60
BtLocaleMgrImpl & btLocaleMgrInstance()
Definition: btlocalemgr.cpp:33