Пример #1
0
 private void CloseMoFile()
 {
     if (mofile != null)
     {
         TFileLocator.ReleaseMoFile(mofile);
         mofile = null;
     }
     OpenHasFailedBefore = false;
 }
Пример #2
0
        private void OpenMoFile()
        {
            string filename;

            // Check if it is already open
            if (mofile != null)
            {
                return;
            }

            // Check if it has been attempted to open the file before
            if (OpenHasFailedBefore)
            {
                return;
            }

            if (SpecificFilename != "")
            {
                filename = SpecificFilename;
#if DXGETTEXTDEBUG
                DebugLogger("Domain " + Domain + " is bound to specific file " + filename);
#endif
            }
            else
            {
                filename = Directory + curlang + Path.DirectorySeparatorChar + "LC_MESSAGES" + Path.DirectorySeparatorChar + Domain + ".mo";
                if (!TFileLocator.FileExists(filename) && !File.Exists(filename))
                {
#if DXGETTEXTDEBUG
                    DebugLogger("Domain " + Domain + ": File does not exist, neither embedded or in file system: " + filename);
#endif
                    filename = Directory + curlang.Substring(0, 2) + Path.DirectorySeparatorChar + "LC_MESSAGES" + Path.DirectorySeparatorChar + Domain + ".mo";
#if DXGETTEXTDEBUG
                    DebugLogger("Domain " + Domain + " will attempt to use this file: " + filename);
#endif
                }
                else
                {
#if DXGETTEXTDEBUG
                    if (TFileLocator.FileExists(filename))
                    {
                        DebugLogger("Domain " + Domain + " will attempt to use this embedded file: " + filename);
                    }
                    else
                    {
                        DebugLogger("Domain " + Domain + " will attempt to use this file that was found on the file system: " + filename);
                    }
#endif
                }
            }
            if (!TFileLocator.FileExists(filename) && !File.Exists(filename))
            {
#if DXGETTEXTDEBUG
                DebugLogger("Domain " + Domain + " failed to locate the file: " + filename);
#endif
                OpenHasFailedBefore = true;
                return;
            }
#if DXGETTEXTDEBUG
            DebugLogger("Domain " + Domain + " now accesses the file.");
#endif
            mofile = TFileLocator.GetMoFile(filename, DebugLogger);

#if DXGETTEXTDEBUG
            if (mofile.isSwappedArchitecture)
            {
                DebugLogger(".mo file is swapped (comes from another CPU architecture)");
            }
#endif

            // Check, that the contents of the file is utf-8
            if (GetTranslationProperty("Content-Type").ToUpper().IndexOf("CHARSET=UTF-8") == -1)
            {
                CloseMoFile();
#if DXGETTEXTDEBUG
                DebugLogger("The translation for the language code " + curlang + " (in " + filename + ") does not have charset=utf-8 in its Content-Type. Translations are turned off.");
#endif
                MessageBox.Show(null, "The translation for the language code " + curlang + " (in " + filename + ") does not have charset=utf-8 in its Content-Type. Translations are turned off.", "Localization problem", MessageBoxButtons.OK);
                Enabled = false;
            }
        }