Bloom.Program.SetUpLocalization C# (CSharp) Method

SetUpLocalization() public static method

public static SetUpLocalization ( ApplicationContainer applicationContainerSource = null ) : void
applicationContainerSource ApplicationContainer
return void
        public static void SetUpLocalization(ApplicationContainer applicationContainerSource = null)
        {
            var applicationContainer = _applicationContainer;
            if (applicationContainerSource != null)
                applicationContainer = applicationContainerSource;
            var installedStringFileFolder = FileLocator.GetDirectoryDistributedWithApplication(true,"localization");
            if (installedStringFileFolder == null)
            {
                // nb do NOT try to localize this...it's a shame, but the problem we're reporting is that the localization data is missing!
                var msg =
                    @"Bloom seems to be missing some of the files it needs to run. Please uninstall Bloom, then install it again. If that's doesn't fix things, please contact us by clicking the ""Details"" button below, and we'd be glad to help.";
                ErrorReport.NotifyUserOfProblem(new ApplicationException("Missing localization directory"), msg);
                // If the user insists on continuing after that, start up using the built-in English.
                // We need an LM, and it needs some folder of tmx files, though it can be empty. So make a fake one.
                // Ideally we would dispose this at some point, but I don't know when we safely can. Normally this should never happen,
                // so I'm not very worried.
                var fakeLocalDir = new TemporaryFolder("Bloom fake localization").FolderPath;
                applicationContainer.LocalizationManager = LocalizationManager.Create("en", "Bloom", "Bloom", Application.ProductVersion, fakeLocalDir, "SIL/Bloom",
                                           Resources.BloomIcon, "[email protected]",
                                            //the parameters that follow are namespace beginnings:
                                           "Bloom");
                return;
            }

            try
            {
                applicationContainer.LocalizationManager = LocalizationManager.Create(Settings.Default.UserInterfaceLanguage,
                                           "Bloom", "Bloom", Application.ProductVersion,
                                           installedStringFileFolder,
                                           "SIL/Bloom",
                                           Resources.BloomIcon, "[email protected]",
                                           //the parameters that follow are namespace beginnings:
                                           "Bloom");

                //We had a case where someone translated stuff into another language, and sent in their tmx. But their tmx had soaked up a bunch of string
                //from their various templates, which were not Bloom standard templates. So then someone else sitting down to localize bloom would be
                //faced with a bunch of string that made no sense to them, because they don't have those templates.
                //So for now, we only soak up new strings if it's a developer, and hope that the Commit process will be enough for them to realize "oh no, I
                //don't want to check that stuff in".

            #if DEBUG
                applicationContainer.LocalizationManager.CollectUpNewStringsDiscoveredDynamically = true;
            #else
                applicationContainer.LocalizationManager.CollectUpNewStringsDiscoveredDynamically = false;
            #endif

                var uiLanguage =   LocalizationManager.UILanguageId;//just feeding this into subsequent creates prevents asking the user twice if the language of their os isn't one we have a tmx for
                var unusedGoesIntoStatic = LocalizationManager.Create(uiLanguage,
                                           "Palaso", "Palaso", /*review: this is just bloom's version*/Application.ProductVersion,
                                           installedStringFileFolder,
                                            "SIL/Bloom",
                                            Resources.BloomIcon, "[email protected]", "SIL");

                Settings.Default.UserInterfaceLanguage = LocalizationManager.UILanguageId;
            }
            catch (Exception error)
            {
                //handle http://jira.palaso.org/issues/browse/BL-213
                if (GetRunningBloomProcessCount() > 1)
                {
                    ErrorReport.NotifyUserOfProblem("Whoops. There is another copy of Bloom already running while Bloom was trying to set up L10NSharp.");
                    Environment.FailFast("Bloom couldn't set up localization");
                }

                if (error.Message.Contains("Bloom.en.tmx"))
                {
                    ErrorReport.NotifyUserOfProblem(error,
                        "Sorry. Bloom is trying to set up your machine to use this new version, but something went wrong getting at the file it needs. If you restart your computer, all will be well.");

                    Environment.FailFast("Bloom couldn't set up localization");
                }

                //otherwise, we don't know what caused it.
                throw;
            }
        }