Exemple #1
0
        void addTranslation(string localeCode)
        {
            if (!string.IsNullOrWhiteSpace(localeCode))
            {
                var path = Resourcer.GetXamlResPath(localeCode);
                if (File.Exists(path)) // get the strings res path and check if it exists
                {
                    MessageBox.Show("This locale code was already added",
                                    "Existing locale", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    statusCSL.SetError("Could not add an already existing locale");

                    return;
                }

                // create the xaml resources file and reload the available locales
                Resourcer.CreateXamlRes(path, false);
                Ensurer.EnsureAppXamlCs();

                loadLocales();

                statusCSL.SetStatus($"New locale {localeCode} has been added successfully");
            }
        }
        public static void ShowAddCustomResource()
        {
            // sanitized path
            string       sanitized = string.Empty;
            DialogResult retry;

            do
            {
                retry = DialogResult.No;
                var result = InputTextBox.Show(
                    "Enter the name of the new custom resources XAML file", "Enter a name",
                    sanitized, MAX_PATH_LENGTH - Resourcer.GetResourcesFolderPath().Length - 7);
                // -7 = -(@"\.xaml".Length + 1) // it must be LESS than, not less or equal ^ (so substract 1 extra)

                if (string.IsNullOrEmpty(result))
                {
                    return;
                }

                sanitized = string.Join("_", result.Split(Path.GetInvalidFileNameChars(),
                                                          StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');

                if (!string.IsNullOrWhiteSpace(sanitized))
                {
                    var path = Resourcer.GetXamlResPath(result);
                    if (File.Exists(path))
                    {
                        retry = MessageBox.Show("A file with this name already exists! Do you want to change it?",
                                                "Existing file", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                        continue;
                    }
                    Resourcer.CreateXamlRes(path, true);
                }
            }while (retry == DialogResult.Yes);
        }