/// <summary> /// Returns true if string contains incorrect translation for japanese. /// </summary> /// <param name="lr"></param> /// <param name="entry"></param> /// <returns></returns> private bool HasIncorrectTranslation(LocResource lr, JapaneseEntry entry) { var startingPoint = 0; // we are doing this in a loop because a string can contain more than 1 occurence of a given term and we want to check them all // using this logic we will skip over any correct translations and report the first incorrect translation while (true) { //check if target string contains the incorrect translation. if it doesn't, skip //we are using a regex in order to ignore false positives where a katakana word is part of a larger word var match = entry.IncorrectJapaneseRegex.Match(lr.TargetStringNoHK.Value, startingPoint); // the incorrect term does not exist at all. if (!match.Success) { return(false); } var incorrectIndex = match.Index; //here we are using a trick based on logic specified by user: //most of correct entries are the same as incorrect ones with extra ‘ー’ at the end. //so we look for the incorrect translation and then make sure that correct translation exists //at the same index. //in the rare case where ‘ー’ is injected in the middle of the translation, we always return true if //incorrect translation is present var correctIndex = lr.TargetStringNoHK.Value.IndexOf(entry.CorrectJapanese, startingPoint, StringComparison.Ordinal); // if the correct translation does not exist in the same place, the translation is not correct if (incorrectIndex != correctIndex) { return(true); } // move the starting point beyond the current substring that we have examined startingPoint = incorrectIndex + match.Length; } }
/// <summary> /// Checks for characters that cannot be accessed from default target input locale identifier (keyboard layout) without the use /// of any modifiers. /// </summary> /// <returns>An collection of characters that cannot be accessed from the default keyboard layout.</returns> private IEnumerable <String> GetIllegalChars(LocResource lr) { // target string to be tested string tgtStr = lr.TargetString; if (String.IsNullOrEmpty(tgtStr)) { return(new string[0]); } // target culture to be tested against var targetLanguageLCID = lr.TargetCulture.Value.LCID; IntPtr inputLocaleIdentifier; // check if the input locale identifier (keyboard layout) has been loaded for the target LCID and load it if it hasn't been. if (!lcidToInputLocaleIdentifier.TryGetValue(targetLanguageLCID, out inputLocaleIdentifier)) { // create hex string for default input for the given LCID in form 0000<hex LCID> var hexStringForDefault = String.Format("0000{0}", targetLanguageLCID.ToString("X4")); inputLocaleIdentifier = LoadKeyboardLayout(hexStringForDefault, 0); if (inputLocaleIdentifier == null) { throw new InvalidOperationException(String.Format("Could not obtain default input locale identifier for LCID ", targetLanguageLCID)); } else { lcidToInputLocaleIdentifier.Add(targetLanguageLCID, inputLocaleIdentifier); } } // check that each character in string is indeed accessible for the input locale identifier return(((IEnumerable <char>)tgtStr).Where(c => !IsCharacterAccessibleFromTargetKeyboard(c, inputLocaleIdentifier)).Select(c => c.ToString())); }
/// <summary> /// Check if the resource is one of the Keytip disambiguation resources we want to check. /// </summary> /// <param name="lr"></param> /// <returns></returns> static private bool IsKeytipDisambiguation(LocResource lr) { var stringId = lr.LSResID.ItemID.StringId; return (stringId.Equals("msoidsChunkCharacter", StringComparison.OrdinalIgnoreCase) || stringId.Equals("msoidsDisambiguationCharacters", StringComparison.OrdinalIgnoreCase) || stringId.Equals("msoidsQATCharacters", StringComparison.OrdinalIgnoreCase) || stringId.Equals("msoidsSpecialCharacterForLowerRibbon", StringComparison.OrdinalIgnoreCase) || stringId.Equals("msoidsSpecialCharacterForUpperRibbon", StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Returns true if the dictionary contains a translation the same culture as this resource /// and the TargetString matches that translation. /// <para/>If the dictionary doesn't contain a translation for that culture, it returns a default value of 'true'. /// Otherwise, false is returned. /// <para/>If false is returned, <paramref name="modifiableMessage"/> is updated to indicate the expected value. /// </summary> /// <param name="dictionary">Dictionary that contains legacy translations from Office 12.</param> /// <param name="modifiableMessage">Message that will go to OSLEBot output. Will be updated by this method when it is about to return false.</param> public static bool MatchesLegacyTranslationFromDictionary(this LocResource me, Dictionary <CultureInfo, string> dictionary, CustomMessage modifiableMessage) { string referenceTranslation; if (dictionary.TryGetValue(me.TargetCulture.Value.BuiltinCultureInfo, out referenceTranslation)) { if (me.TargetString.Equals(referenceTranslation)) { return(true); } modifiableMessage.SetInit("Current translation is different from Office12 version."); modifiableMessage.Expected = referenceTranslation; return(false); } return(true); //When the dictionary doesn't contain a reference translation for this culture, return a default of 'true'. }
/// <summary> /// Searches the target string for each of the known branding names defined in brandingNameIndex. /// If found, looks for the approved translation for the target culture. /// </summary> /// <param name="lr"></param> /// <returns>A collection of English Branding Names for which no correct translation was found. Correct Translation is also included for reporting purposes.</returns> private InvalidBranding[] GetInvalidBranding(LocResource lr) { var targetCulture = lr.TargetCulture.Value.BuiltinCultureInfo; return(( from indexEntry in brandingNameIndex where lr.SourceStringNoHK.RegExp(indexEntry.EnglishBrandingEntry.Regex) let locEntry = indexEntry.GetLocalizedBrandingEntry(targetCulture) where !lr.TargetStringNoHK.RegExp(locEntry.Regex) select new InvalidBranding { BrandingName = indexEntry.EnglishBrandingEntry.BrandingName, CorrectTranslation = locEntry.BrandingName } ).ToArray()); }
/// <summary> /// Create instances of LocResource, adding them to the private objects collection. /// </summary> /// <param name="entry"></param> private void ProcessResourceFileEntry(ResourceFileEntry entry) { // Create Property provider by matching property adapters with data sources // PropertyProvider is called by ResourceStaticAnalysis when code attempts to retrieve a property that has not yet been created var pp = new PropertyProvider(); // Add a pair: property adapter and an object that serves as source foreach (var adapter in resourceFilePropertyAdapters) { pp.AddPropertyAdapterDataSourcePair(adapter, entry); } if (configDictPropertyAdapters != null) { foreach (var adapter in configDictPropertyAdapters) { pp.AddPropertyAdapterDataSourcePair(adapter, myConfig); } } // Initialize an instance of LocResource using the PropertyProvider built above var lr = new LocResource(pp); foreach (var adapter in selfPropertyAdapters) { // Now, add one more poperty adapter that uses the LocResource object itself as data source. // This one builds properties from existing properties. pp.AddPropertyAdapterDataSourcePair(adapter, lr); } // This reduces amount of memory used by object by compacting internal representation. pp.Compact(); // Add to the list of all objects being constructed by this adapter. objects.Add(lr); }
/// <summary> /// Returns true if SourceString == TargetString. False otherwise. /// </summary> public static bool SourceEqualsTarget(this LocResource me) { return(me.SourceStringNoHK.Value == me.TargetStringNoHK.Value); }
private static Property GetSelfProperty(LocResource.LocResourceProps propertyId, LocResource lr) { if (Object.ReferenceEquals(lr, null)) { throw new NullReferenceException(String.Format(CultureInfo.CurrentCulture, "DataSource must not be null. DataSource name: {0}", lr.GetType().Name)); } switch (propertyId) { case LocResource.LocResourceProps.ResourceId: return(new StringProperty((byte)propertyId, lr.ResourceId)); case LocResource.LocResourceProps.SourceString: return(new StringProperty((byte)propertyId, lr.SourceString)); case LocResource.LocResourceProps.Comments: return(new StringProperty((byte)propertyId, lr.Comments)); case LocResource.LocResourceProps.FilePath: return(new StringProperty((byte)propertyId, lr.FilePath)); default: throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "Cannot provide property {0} from datasource of type {1}.", propertyId.ToString(), lr.GetType().Name)); } }
static private bool ResourceIsAKeytipOverride(LocResource lr) { return(lr.LSResID.Value.IndexOf("KeytipOverride", StringComparison.OrdinalIgnoreCase) > -1); }