Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringLocalizer"></param>
 /// <param name="valueParser"></param>
 public StringLocalizerAsset(IStringLocalizer stringLocalizer, IStringFormatParser valueParser = default)
 {
     this.stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
     this.culture_map     = new ConcurrentDictionary <CultureInfo, StringLocalizerAsset>();
     this.createFunc      = ci => new StringLocalizerAsset(stringLocalizer.WithCulture(ci), ci);
     this.ValueParser     = ValueParser ?? CSharpFormat.Default;
 }
Esempio n. 2
0
 /// <summary>
 /// Create factory asset.
 /// </summary>
 /// <param name="stringLocalizerFactory"></param>
 /// <param name="valueParser"></param>
 public StringLocalizerFactoryAsset(IStringLocalizerFactory stringLocalizerFactory, IStringFormatParser valueParser = default)
 {
     this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory));
     this.map_by_type            = new ConcurrentDictionary <String, StringLocalizerAsset.Type>();
     this.map_by_location        = new ConcurrentDictionary <Pair <String, String>, StringLocalizerAsset.Location>();
     createByTypeFunc            = typeName =>
     {
         Type type = Type.GetType(typeName, throwOnError: true);
         return(new StringLocalizerAsset.Type(stringLocalizerFactory.Create(type), type, null));
     };
     createByLocationFunc = location => new StringLocalizerAsset.Location(stringLocalizerFactory.Create(location.a, location.b), location.a, location.b, null);
     this.ValueParser     = ValueParser ?? CSharpFormat.Default;
 }
 /// <summary>
 /// Parse string key of each line into <see cref="ILine"/> by using <paramref name="lineFormat"/>.
 ///
 /// If parse fails, then skips the key, doesn't throw exception.
 /// </summary>
 /// <param name="lines"></param>
 /// <param name="lineFormat"><see cref="ILineFormatParser"/> parses string to line.</param>
 /// <param name="valueParser"></param>
 /// <returns>lines with <see cref="ILine"/> keys</returns>
 public static IEnumerable <ILine> ToLines(this IEnumerable <KeyValuePair <string, string> > lines, ILineFormat lineFormat, IStringFormatParser valueParser)
 {
     foreach (var line in lines)
     {
         ILine l;
         if (lineFormat.TryParse(line.Key, out l))
         {
             yield return(line.Value == null ? l : l.String(valueParser.Parse(line.Value)));
         }
     }
 }
 /// <summary>
 /// Construct an <see cref="IAsset"/> that reads strings and resources from <see cref="ResourceManager"/>.
 ///
 /// </summary>
 /// <param name="resourceManager">source of language strings and resource files</param>
 /// <param name="lineFormat">policy that converts <see cref="ILine"/> into keys that correlate with keys in <paramref name="resourceManager"/>.</param>
 /// <param name="parser"></param>
 public ResourceManagerAsset(ResourceManager resourceManager, ILineFormat lineFormat, IStringFormatParser parser = default)
 {
     this.ResourceManager = resourceManager ?? throw new ArgumentNullException(nameof(resourceManager));
     this.namePolicy      = lineFormat ?? throw new ArgumentNullException(nameof(lineFormat));
     this.ValueParser     = parser ?? CSharpFormat.Default;
 }
Esempio n. 5
0
 /// <summary>
 /// Convert <paramref name="lines"/> to asset key lines.
 /// </summary>
 /// <param name="lines"></param>
 /// <param name="lineFormat"></param>
 /// <param name="valueParser"></param>
 /// <returns></returns>
 public static IEnumerable <KeyValuePair <string, IString> > ToStringLines(this IEnumerable <KeyValuePair <ILine, string> > lines, ILineFormat lineFormat, IStringFormatParser valueParser)
 => lines.Select(line => new KeyValuePair <string, IString>((lineFormat ?? DefaultPolicy).Print(line.Key), valueParser.Parse(line.Value)));
Esempio n. 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringLocalizer"></param>
 /// <param name="basename">Embed location, e.g. "Resources" folder in an assembly</param>
 /// <param name="location">Assembly name</param>
 /// <param name="culture"></param>
 /// <param name="valueParser"></param>
 public Location(IStringLocalizer stringLocalizer, string basename, string location, CultureInfo culture, IStringFormatParser valueParser = default) : base(stringLocalizer, culture, valueParser)
 {
     this.basename   = basename ?? throw new ArgumentNullException(nameof(basename));
     this.location   = location ?? throw new ArgumentNullException(nameof(location));
     this.createFunc = ci => new Location(stringLocalizer.WithCulture(ci), basename, location, ci);
 }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stringLocalizer"></param>
 /// <param name="type"></param>
 /// <param name="culture"></param>
 /// <param name="valueParser"></param>
 public Type(IStringLocalizer stringLocalizer, System.Type type, CultureInfo culture, IStringFormatParser valueParser = default) : base(stringLocalizer, culture, valueParser)
 {
     this.type       = type ?? throw new ArgumentNullException(nameof(type));
     this.createFunc = ci => new Type(stringLocalizer.WithCulture(ci), type, ci);
 }
Esempio n. 8
0
 /// <summary>
 /// Create reader
 /// </summary>
 /// <param name="ext"></param>
 /// <param name="valueParser"></param>
 public ResourcesLineReader(string ext, IStringFormat valueParser)
 {
     this.Extension   = ext;
     this.ValueParser = valueParser as IStringFormatParser ?? throw new ArgumentNullException(nameof(valueParser));
 }