/// <summary> /// Method called by OSLEBot engine for every resource. /// This method contains one or more calls to Check() method that log messages to OSLEBot output when criteria specified in Check() are met. /// </summary> protected override void Run() { // check initial condition for file type and parser and skip the check altogether if they are not met. var currentResource = (LocResource)CurrentCO; if (!(currentResource.Document.Value.ParserId.Equals(localBindingParserID, StringComparison.OrdinalIgnoreCase) && currentResource.FileName.Value.EndsWith(StringComparison.OrdinalIgnoreCase, fileExtensions))) { return; } // check for unescaped characters, excluding double-quote to reduce noise Check(lr => mc.SetContext(lr.TargetString.RegExpMatches(unescapedCharacters)).Any(), mc.SetInit("Translation contains invalid characters that need to be escaped using character entity references: ")); // check for double-quote in target, but only if source does not contain a double-quote: // exclude .resx files Check(lr => !lr.FileName.Value.EndsWith(StringComparison.OrdinalIgnoreCase, ".resx") && lr.TargetString.Contains("\"") && !lr.SourceString.Contains("\""), "Translation contains a double-quote character, but source doesn't. Use entity reference " instead of this character."); // check for invalid XML references Check(lr => mc.SetContext(lr.TargetString.RegExpMatches(invalidEntityReferences)).Any(), mc.SetInit("Translation contains invalid XML references: ")); // check for possible double-escaping Check(lr => mc.SetContext(lr.TargetString.RegExpMatches(possibleDoubleEscaping)).Any(), mc.SetInit("Translation contains possible double-escaping of ampersand character: ")); }
protected override void Run() { var currentLocResource = (LocResource)CurrentCO; // check if source string contains the "all rights reserved" expression". if not, ignore the check. if (currentLocResource.SourceStringNoHK.Contains(StringComparison.OrdinalIgnoreCase, "All rights reserved")) { var targetCultureInfo = currentLocResource.TargetCulture.Value.BuiltinCultureInfo; string approvedTranslation = null; // get the approvedTranslation for the current target language. if (approvedTranslations.TryGetValue(targetCultureInfo, out approvedTranslation)) { // set message context to the approved translation value, so we append it to the message. mc.SetContext(approvedTranslation); Check(lr => !lr.TargetString.Value.Contains(StringComparison.OrdinalIgnoreCase, approvedTranslation), mc.SetInit("Incorrect translation for term \"All rights reserved\". Should be: ") ); } else { Check(lr => true, String.Format("No approved translation for term \"All rights reserved\" defined in Cerberus for culture {0}. Cannot execute check.", targetCultureInfo.Name)); } } }
/// <summary> /// Method called by OSLEBot engine for every resource. /// This method contains one or more calls to Check() method that log messages to OSLEBot output when criteria specified in Check() are met. /// </summary> protected override void Run() { Check(lr => IsKeytipDisambiguation(lr) && mc.SetContext(GetIllegalChars(lr)).Any() , mc.SetInit("This is a Keytip Disambiguation string and it must contain characters available in the default target keyboard layout. The following characters must not be used: ")); }
protected override void Run() { // Check that the SourceString contains a placeholder that is not defined in the Comments. Check( lr => _mc.SetContext( lr.SourceString.Value.RegExpMatches(_placeholderRegex) .Where(sourceTerm => !lr.SourceString.Value.TrimEnd('\r', '\n').Equals(sourceTerm)) .Where(strph => lr.Comments.RegExpMatches(_placeholderRegex).All(cmph => cmph != strph))) .Any(), _mc.SetInit("Placeholder(s) present in string but not in comment: ")); }
/// <summary> /// Method called by OSLEBot engine for every resource. /// This method contains one or more calls to Check() method that log messages to OSLEBot output when criteria specified in Check() are met. /// </summary> protected override void Run() { // current resource object, for easy access. var currentResource = (LocResource)CurrentCO; // all token names present in the Source String var srcTokenNames = tokenChecker.ExtractTokenNames(currentResource.SourceString); // all token names present in the Target String var tgtTokenNames = tokenChecker.ExtractTokenNames(currentResource.TargetString); ///<check> ///Broken token syntax ///</check> Check(lr => mc.SetContext(tokenChecker.ReportSyntaxErrorsForTokens(srcTokenNames, currentResource.TargetString).Select(issue => issue.Message)).Any(), mc.SetInit("Translation contains the following token names with incorrect markups: ")); /// possible misspelled token names in target. we will be reusing this in other checks later to filter out some results. /// helper methods returns a dictionary that maps each source token name to a list of possible misspellings of the token - we are /// using this information in Tokens Added and Tokens Removed checks to filer out misspelled tokens from the results. var misspelledTokenNames = tokenChecker.ExtractMisspelledTokens(srcTokenNames, currentResource.TargetString); ///<check> ///Misspelled token names ///</check> // flatten the information about what tokens were potentially misspelled into. mc.SetContext(misspelledTokenNames.Select(entry => String.Format("{0} => {1}", entry.Key, String.Join(", ", entry.Value.ToArray())))); Check(lr => misspelledTokenNames.Any(), mc.SetInit("Translation contains posssibly misspelled token names: ")); ///<check> ///Tokens added. ///</check> Check(lr => mc.SetContext(tgtTokenNames.Except(srcTokenNames).Except(misspelledTokenNames.Values.SelectMany(list => list))).Any(), mc.SetInit("Translation contains the following extra tokens that do not exist in source string: ")); ///<check> ///Tokens removed. ///</check> Check(lr => mc.SetContext(srcTokenNames.Except(tgtTokenNames).Except(misspelledTokenNames.Keys)).Any(), mc.SetInit("Translation is missing the following tokens that exist in source string: ")); }
protected override void Run() { // Checks for the presence of a pattern added by the DataAdapter parsers to indicate a duplicate ResourceId // If present, the context is set to the duplicate number (the nth duplicate) for this ResourceId // If not present, the context is set to the string value // Returns true if the context and string value are different Check( lr => _mc.SetContext( lr.ResourceId.Value.Substring(lr.ResourceId.Value.Contains(_dupPattern) ? lr.ResourceId.Value.IndexOf(_dupPattern, StringComparison.Ordinal) + _dupPattern.Length : 0)) != lr.ResourceId.Value, _mc.SetInit( "One or more duplicate entries detected in the file for this resource ID. This is duplicate number:")); }
/// <summary> /// Method called by OSLEBot engine for every resource. /// This method contains one or more calls to Check() method that log messages to OSLEBot output when criteria specified in Check() are met. /// </summary> protected override void Run() { Check(lr => mc.SetContext(lr.TargetString.RegExpMatches(detectIncorrectKoreanPostPositionSequence)).Any(), mc.SetInit(defaultMessage)); }
protected override void Run() { Check(resource => mc.SetContext(GetVowels(resource.SourceString.ToString()).ToString()).Any(), mc.SetInit("Vowels found in SourceString: ")); }