/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> /// <param name="culture">The culture for which to perform the match.</param> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="rule">The rule which defines how to perform the match.</param> /// <returns>The variant of <paramref name="source"/> which is the best match for <paramref name="target"/> according to the specified rule.</returns> public static String MatchVariant(String culture, LocalizedString source, LocalizedStringVariant target, StringSegment rule) { Contract.RequireNotEmpty(culture, nameof(culture)); Contract.Require(target, nameof(target)); return(MatchVariantInternal(culture, source, target, rule)); }
/// <summary> /// Matches a source string to a target variant according to the current culture and the specified rule. /// </summary> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="rule">The rule which defines how to perform the match.</param> /// <returns>The variant of <paramref name="source"/> which is the best match for <paramref name="target"/> according to the specified rule.</returns> public static String MatchVariant(LocalizedString source, LocalizedStringVariant target, String rule) { Contract.Require(target, nameof(target)); Contract.RequireNotEmpty(rule, nameof(rule)); return(MatchVariantInternal(CurrentCulture, source, target, rule)); }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> private static String MatchVariantInternal(String culture, LocalizedString source, LocalizedStringVariant target, StringSegment rule) { Dictionary <String, LocalizationMatchEvaluator> registry; if (!registeredMatchEvaluators.TryGetValue(culture, out registry)) { return(null); } foreach (var kvp in registry) { if (rule.Equals(kvp.Key)) { return((kvp.Value == null) ? null : kvp.Value(source, target)); } } return(null); }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> private static String MatchVariantInternal(String culture, LocalizedString source, LocalizedStringVariant target, String rule) { Dictionary <String, LocalizationMatchEvaluator> registry; if (!registeredMatchEvaluators.TryGetValue(culture, out registry)) { return(null); } LocalizationMatchEvaluator evaluator; if (!registry.TryGetValue(rule, out evaluator)) { return(null); } return((evaluator == null) ? null : evaluator(source, target)); }
/// <summary> /// Initializes a new instance of the LocalizedStringVariantResult class. /// </summary> /// <param name="variant">The string variant being examined.</param> internal LocalizedStringVariantResult(LocalizedStringVariant variant) { this.variant = variant; }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> private static String MatchVariantInternal(String culture, LocalizedString source, LocalizedStringVariant target, String rule) { Dictionary<String, LocalizationMatchEvaluator> registry; if (!registeredMatchEvaluators.TryGetValue(culture, out registry)) return null; LocalizationMatchEvaluator evaluator; if (!registry.TryGetValue(rule, out evaluator)) return null; return (evaluator == null) ? null : evaluator(source, target); }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> private static String MatchVariantInternal(String culture, LocalizedString source, LocalizedStringVariant target, StringSegment rule) { Dictionary<String, LocalizationMatchEvaluator> registry; if (!registeredMatchEvaluators.TryGetValue(culture, out registry)) return null; foreach (var kvp in registry) { if (rule.Equals(kvp.Key)) { return (kvp.Value == null) ? null : kvp.Value(source, target); } } return null; }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> /// <param name="culture">The culture for which to perform the match.</param> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="rule">The rule which defines how to perform the match.</param> /// <returns>The variant of <paramref name="source"/> which is the best match for <paramref name="target"/> according to the specified rule.</returns> public static String MatchVariant(String culture, LocalizedString source, LocalizedStringVariant target, StringSegment rule) { Contract.RequireNotEmpty(culture, "culture"); Contract.Require(target, "target"); return MatchVariantInternal(culture, source, target, rule); }
/// <summary> /// Matches a source string to a target variant according to the current culture and the specified rule. /// </summary> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="rule">The rule which defines how to perform the match.</param> /// <returns>The variant of <paramref name="source"/> which is the best match for <paramref name="target"/> according to the specified rule.</returns> public static String MatchVariant(LocalizedString source, LocalizedStringVariant target, StringSegment rule) { Contract.Require(target, "target"); return MatchVariantInternal(CurrentCulture, source, target, rule); }
/// <summary> /// Matches a source string to a target variant according to the specified culture and rule. /// </summary> /// <param name="culture">The culture for which to perform the match.</param> /// <param name="source">The source string.</param> /// <param name="target">The target string.</param> /// <param name="rule">The rule which defines how to perform the match.</param> /// <returns>The variant of <paramref name="source"/> which is the best match for <paramref name="target"/> according to the specified rule.</returns> public static String MatchVariant(String culture, LocalizedString source, LocalizedStringVariant target, String rule) { Contract.RequireNotEmpty(culture, nameof(culture)); Contract.Require(target, nameof(target)); Contract.RequireNotEmpty(rule, nameof(rule)); return MatchVariantInternal(culture, source, target, rule); }
/// <summary> /// Creates a pseudolocalized copy of the specified source string. /// </summary> /// <param name="source">The source string to pseudolocalize.</param> /// <returns>A copy of the source string that is pseudolocalized.</returns> internal static LocalizedString CreatePseudolocalized(LocalizedString source) { Contract.Require(source, "source"); var pseudoString = new LocalizedString(Localization.PseudolocalizedCulture, source.Key, source.ContainsHtmlEncodedCharacters, source.PseudolocalizationDisabled); foreach (var variant in source.variants) { if (pseudoString.PseudolocalizationDisabled) { var pseudoVariant = new LocalizedStringVariant(pseudoString, variant.Value.Group, variant.Value.Value, variant.Value.Properties); pseudoString.variants[variant.Key] = pseudoVariant; } else { var pseudoText = String.Empty; if (pseudoString.ContainsHtmlEncodedCharacters) { pseudoText = Uri.UnescapeDataString(variant.Value.Value); pseudoText = PseudolocalizeString(pseudoText); pseudoText = Uri.EscapeDataString(pseudoText); } else { pseudoText = PseudolocalizeString(variant.Value.Value); } var pseudoVariant = new LocalizedStringVariant(pseudoString, variant.Value.Group, pseudoText, variant.Value.Properties); pseudoString.variants[variant.Key] = pseudoVariant; } } return pseudoString; }
/// <summary> /// Adds an argument to the string formatter. /// </summary> /// <param name="value">The value to add as an argument.</param> public void AddArgument(LocalizedStringVariant value) { arguments.Add(new StringFormatterArgument(value)); }