// update a string key to a new key name public static void UpdateStringKey(string oldKey, string newKey) { Ensurer.EnsureEverything(); updateStringKey(oldKey, newKey, string.Empty); foreach (var locale in GetStringsResLocales()) { updateStringKey(oldKey, newKey, locale); } var oldCs = GetStringCall(oldKey, false); var oldXaml = GetStringCall(oldKey, true); var newCs = GetStringCall(newKey, false); var newXaml = GetStringCall(newKey, true); foreach (var file in VsUtils.GetProjectFiles(VsUtils.GetCurrentProject())) { if (file.EndsWith(extensionCs)) { updateSource(file, oldCs, newCs); } else if (file.EndsWith(extensionXaml)) { updateSource(file, oldXaml, newXaml); } } }
// create the resources file in the desired path public static void CreateXamlRes(string path, bool openInEditor) { StringsXMLEditor.CreateDocument(path); VsUtils.AddFileIfUnexisting(VsUtils.GetCurrentProject(), path); Ensurer.EnsureAppXaml(); if (openInEditor) { VsUtils.OpenInEditor(path); } Ensurer.EnsureEverything(); }
public ManageStringsForm() { InitializeComponent(); Ensurer.EnsureEverything(); loadLocales(); if (StringResources == null) { updateTranslationsList(); } filterTypeCB.SelectedIndex = 1; }
// delete a strings resource provided a locale public static void DeleteStrings(string locale = null) { var resFile = Path.Combine(GetResourcesFolderPath(), GetStringsResName(locale)); if (File.Exists(resFile)) { try { VsUtils.DeleteFile(VsUtils.GetCurrentProject(), resFile); Ensurer.EnsureAppXaml(); } catch { } } }
// add a string to the strings resources // returns a call (as C# code) to retrieve the new added resource public static string AddString(KeyValuePair <string, string> keyValue, bool isXaml, bool resourceExisted, string locale = null) { Ensurer.EnsureStringResources(); // TODO no need to save if addstring document is used nowhere else... if (!resourceExisted) { var resFile = GetResourcePath(GetStringsResName(locale)); StringsXMLEditor.AddString(resFile, keyValue.Key, keyValue.Value); } Ensurer.EnsureEverything(); return(GetStringCall(keyValue.Key, isXaml)); }
// are the current settings the old ones (i.e. we reset the settings)? void checkChanges(bool currentOld = false) { // no loaded project, no need to check changes if (VsUtils.GetCurrentProject() == null) { return; } Settings.UseStaticResourceXAML = !useDynamicXamlCB.Checked; // if the settings changed and they're not empty, update them if (Settings.SetLocaleOnStartup != selectLocaleStartCB.Checked) { Ensurer.EnsureAppXamlCs(); } if (Settings.ResourcesFolderName != resFolderNameTB.Text && resFolderNameTB.Text.Length > 0) { if (currentOld) // change the order depending on which are the old settings { Ensurer.RenameResFolder(resFolderNameTB.Text, Settings.ResourcesFolderName); } else { Ensurer.RenameResFolder(Settings.ResourcesFolderName, resFolderNameTB.Text); } } if (Settings.ResourcesManagerName != resManNameTB.Text && resManNameTB.Text.Length > 0) { if (currentOld) { Ensurer.RenameResManager(resManNameTB.Text, Settings.ResourcesManagerName); } else { Ensurer.RenameResManager(Settings.ResourcesManagerName, resManNameTB.Text); } } }
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"); } }