/// <summary> /// Inserts the key value into the given string resources. /// </summary> /// <param name="section">Section.</param> /// <param name="key">Key.</param> /// <param name="value">Value.</param> private void InsertKeyValueIntoSection(StringResources res, string section, string key, string value) { if (res.HasKey(section, key)) { // The same resource file has duplicate key. Select which key you want. var ib = new InputBuilder(); ib.AddAction(key, value, () => { res.AddValue(section, key, value); }); ib.AddAction(key, res[section].resources[key], () => { // No action required. }); console.NL(2); console.WL("File => " + currentFile.FullName + " line: " + currentLine + " column: " + currentColumn); console.NL(); console.WL("ResourceCompiler has detected a duplicate key in section: " + section); console.RequestListItemSelection("Please select which value you would prefer for key {" + key + " in section '" + section + "'}", ib); } else { res.AddValue(section, key, value); } }
/// <summary> /// Compares the content of all of the sections to ensure that the resources are used on all platforms. /// </summary> /// <param name="sections">Sections.</param> private StringResources.Section CombineSections(StringResources.Section[] sections) { Clear(); if (sections == null || sections.Length <= 0) { Error("Found and empty section when merging sections"); } var ret = new StringResources.Section() { name = sections[0].name }; var keys = new HashSet <string>(); foreach (var section in sections) { // Generate a union of all the keys in the sections. foreach (var key in section.resources.Keys) { keys.Add(key); } } foreach (var key in keys) { Clear(); var options = new List <string>(); var ib = new InputBuilder(); var i = 0; foreach (var section in sections) { if (section.ContainsKey(key)) { options.Add(section.resources[key]); ib.AddAction(i++ + "", section.resources[key], () => { ret.resources[key] = section.resources[key]; }); } } var similar = true; for (int j = 1; j < options.Count; j++) { if (!sections[0].ContainsKey(key) || !sections[j].ContainsKey(key) || (!sections[0].resources[key].Equals(sections[j].resources[key]))) { similar = false; break; } } if (!similar) { // We need to ask the user which option to use. // We need to build the actions list. ib.AddAction(i++ + "", "Use keep both (do this only when there is a distinction between platform strings)", () => { WL("Failed to keep both"); }); WL("Found multiple values for key [" + key + "]"); context.RequestListItemSelection("Please select the value that the key should be.", ib); } } return(ret); }