public string[] GetAllTranslations(string translationKey, string context, IPluralBuilder pluralBuilder) { if (!_catalog.Translations.ContainsKey(translationKey)) { return new string[] {} } ; if (!string.IsNullOrWhiteSpace(context)) { translationKey = context + Catalog.CONTEXT_GLUE + translationKey; } var translations = _catalog.GetTranslations(translationKey); if (translations.Length != pluralBuilder.NumberOfPlurals) { return new string[] {} } ; return(translations); } } }
private void SetStringArrayProperty(ITranslatable o, PropertyInfo property, IPluralBuilder pluralBuilder, ITranslationSource translationSource) { var context = ContextAttribute.GetValue(property); var value = (string[])property.GetValue(o, null); if (value.Length != 2) { throw new InvalidDataException( $"The plural string for key {property.Name} must contain two strings: a singular and a plural form. It contained {value.Length} strings."); } var translations = translationSource.GetAllTranslations(value[0], context, pluralBuilder); if (translations.Length == pluralBuilder.NumberOfPlurals) { property.SetValue(o, translations, null); } }
private void SetStringArrayProperty(PropertyInfo property, IPluralBuilder pluralBuilder, ITranslationSource translationSource, ITranslatable targetTranslation, ITranslatable baseTranslation) { var context = ContextAttribute.GetValue(property); var sourceStrings = (string[])property.GetValue(baseTranslation, null); if (sourceStrings.Length != 2) { throw new InvalidDataException( $"The plural string for key {property.Name} must contain two strings: a singular and a plural form. It contained {sourceStrings.Length} strings."); } var translations = translationSource.GetAllTranslations(sourceStrings[0], context, pluralBuilder); if (translations.Length == pluralBuilder.NumberOfPlurals) { property.SetValue(targetTranslation, translations, null); } else { property.SetValue(targetTranslation, sourceStrings, null); } }
private void SetPluralbuilderProperty(ITranslatable translatable, PropertyInfo property, IPluralBuilder pluralBuilder) { property.SetValue(translatable, pluralBuilder, null); }