Runs.
[dcpomatic.git] / src / lib / util.cc
index d1450ccc2a4aecc7860eeb7cfa5dcf7430a1233e..0247408679f172a3ae29b5737083e8e625b0debc 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,50 @@ 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)
+{
+#ifdef DVDOMATIC_POSIX
+       lang += ".UTF8";
+#endif
+
+       if (!lang.empty ()) {
+               /* Override our environment language; this is essential on
+                  Windows.
+               */
+               char cmd[64];
+               snprintf (cmd, sizeof(cmd), "LANGUAGE=%s", lang.c_str ());
+               putenv (cmd);
+               snprintf (cmd, sizeof(cmd), "LANG=%s", lang.c_str ());
+               putenv (cmd);
+       }
+
+       setlocale (LC_ALL, "");
+       textdomain ("libdvdomatic");
+
+#ifdef DVDOMATIC_WINDOWS
+       bindtextdomain ("libdvdomatic", mo_path().string().c_str());
+#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.
@@ -306,11 +347,11 @@ md5_digest (void const * data, int size)
  *  @return MD5 digest of file's contents.
  */
 string
-md5_digest (string file)
+md5_digest (boost::filesystem::path file)
 {
-       ifstream f (file.c_str(), ios::binary);
+       ifstream f (file.string().c_str(), ios::binary);
        if (!f.good ()) {
-               throw OpenFileError (file);
+               throw OpenFileError (file.string());
        }
        
        f.seekg (0, ios::end);
@@ -885,12 +926,12 @@ audio_channel_name (int c)
           enhancement channel (sub-woofer)./
        */
        string const channels[] = {
-               "Left",
-               "Right",
-               "Centre",
-               "Lfe (sub)",
-               "Left surround",
-               "Right surround",
+               _("Left"),
+               _("Right"),
+               _("Centre"),
+               _("Lfe (sub)"),
+               _("Left surround"),
+               _("Right surround"),
        };
 
        return channels[c];
@@ -962,17 +1003,17 @@ FrameRateConversion::FrameRateConversion (float source, int dcp)
        change_speed = !about_equal (source * factor(), dcp);
 
        if (!skip && !repeat && !change_speed) {
-               explanation = _("DCP and source have the same rate.\n");
+               description = _("DCP and source have the same rate.\n");
        } else {
                if (skip) {
-                       explanation = _("DCP will use every other frame of the source.\n");
+                       description = _("DCP will use every other frame of the source.\n");
                } else if (repeat) {
-                       explanation = _("Each source frame will be doubled in the DCP.\n");
+                       description = _("Each source frame will be doubled in the DCP.\n");
                }
 
                if (change_speed) {
-                       float const pc = (source * factor()) * 100 / dcp;
-                       explanation += String::compose (_("DCP will run at %1%% of the source speed."), pc);
+                       float const pc = dcp * 100 / (source * factor());
+                       description += String::compose (_("DCP will run at %1%% of the source speed."), pc);
                }
        }
 }