+
+void
+dcpomatic_setup_i18n ()
+{
+ int language = wxLANGUAGE_DEFAULT;
+
+ boost::optional<string> config_lang = Config::instance()->language ();
+ if (config_lang && !config_lang->empty ()) {
+ wxLanguageInfo const * li = wxLocale::FindLanguageInfo (std_to_wx (config_lang.get ()));
+ if (li) {
+ language = li->Language;
+ }
+ }
+
+ wxLocale* locale = 0;
+ if (wxLocale::IsAvailable (language)) {
+ locale = new wxLocale (language, wxLOCALE_LOAD_DEFAULT);
+
+#ifdef DCPOMATIC_WINDOWS
+ locale->AddCatalogLookupPathPrefix (std_to_wx (mo_path().string()));
+#endif
+
+#ifdef DCPOMATIC_POSIX
+ locale->AddCatalogLookupPathPrefix (POSIX_LOCALE_PREFIX);
+#endif
+
+#ifdef DCPOMATIC_LINUX
+ /* We have to include the wxWidgets .mo in our distribution,
+ so we rename it to avoid clashes with any other installation
+ of wxWidgets.
+ */
+ locale->AddCatalog (wxT ("dcpomatic-wxstd"));
+#endif
+
+ locale->AddCatalog (wxT ("libdcpomatic-wx"));
+ locale->AddCatalog (wxT ("dcpomatic"));
+
+ if (!locale->IsOk()) {
+ delete locale;
+ locale = new wxLocale (wxLANGUAGE_ENGLISH);
+ }
+ }
+
+ if (locale) {
+ dcpomatic_setup_gettext_i18n (wx_to_std (locale->GetCanonicalName ()));
+ }
+}
+
+int
+wx_get (wxSpinCtrl* w)
+{
+ return w->GetValue ();
+}
+
+int
+wx_get (wxChoice* w)
+{
+ return w->GetSelection ();
+}
+
+double
+wx_get (wxSpinCtrlDouble* w)
+{
+ return w->GetValue ();
+}
+
+/** @param s String of the form Context|String
+ * @return translation, or String if no translation is available.
+ */
+wxString
+context_translation (wxString s)
+{
+ wxString t = wxGetTranslation (s);
+ if (t == s) {
+ /* No translation; strip the context */
+ int c = t.Find (wxT ("|"));
+ if (c != wxNOT_FOUND) {
+ t = t.Mid (c + 1);
+ }
+ }
+
+ return t;
+}