Improve language setup.
[dcpomatic.git] / src / lib / util.cc
index 7395bde2e016aa6fab63cb83a4e255df7de8901d..2e467125181afe6a3c75a2848d625c0101c8ce98 100644 (file)
@@ -235,9 +235,6 @@ seconds (struct timeval t)
 void
 dvdomatic_setup ()
 {
-       bindtextdomain ("libdvdomatic", LOCALE_PREFIX);
-       setlocale (LC_ALL, "");
-       
        avfilter_register_all ();
        
        Format::setup_formats ();
@@ -249,6 +246,41 @@ dvdomatic_setup ()
        ui_thread = this_thread::get_id ();
 }
 
+#ifdef DVDOMATIC_WINDOWS
+boost::filesystem::path
+mo_path ()
+{
+       wchar_t buffer[512];
+       GetModuleFileName (0, buffer, 512 * sizeof(wchar_t));
+       boost::filesystem::path p (buffer);
+       p = p.parent_path ();
+       p = p.parent_path ();
+       p /= "locale";
+       return p;
+}
+#endif
+
+void
+dvdomatic_setup_i18n (string lang)
+{
+       setlocale (LC_ALL, "");
+       textdomain ("libdvdomatic");
+       
+#ifdef DVDOMATIC_WINDOWS
+       string const e = "LANGUAGE=" + lang;
+       putenv (e.c_str());
+
+       bindtextdomain ("libdvdomatic", mo_path().string().c_str());
+#else
+       /* Hack to silence warning */
+       lang.clear ();
+#endif 
+
+#ifdef DVDOMATIC_POSIX
+       bindtextdomain ("libdvdomatic", POSIX_LOCALE_PREFIX);
+#endif 
+}
+
 /** @param start Start position for the crop within the image.
  *  @param size Size of the cropped area.
  *  @return FFmpeg crop filter string.
@@ -971,7 +1003,7 @@ FrameRateConversion::FrameRateConversion (float source, int dcp)
                }
 
                if (change_speed) {
-                       float const pc = dcp / ((source * factor()) * 100);
+                       float const pc = dcp * 100 / (source * factor());
                        description += String::compose (_("DCP will run at %1%% of the source speed."), pc);
                }
        }