Ejemplo n.º 1
0
 internal LocalizedStringBuilder(LanguageDefinition definition, string key)
 {
     _definition = definition;
     _key = key;
     _contexts = new Dictionary<string, string>();
     _parameters = new List<object>();
 }
Ejemplo n.º 2
0
 internal LocalizedStringBuilder(LanguageDefinition definition, string key)
 {
     _definition = definition;
     _key        = key;
     _contexts   = new Dictionary <string, string>();
     _parameters = new List <object>();
 }
Ejemplo n.º 3
0
        public void Add(LanguageDefinition languageDefinition)
        {
            if (_definition == null)
            {
                _definition = languageDefinition;
                return;
            }

            _definition.Contexts.AddRange(languageDefinition.Contexts);
            foreach (var value in languageDefinition.Values)
                _definition.Values[value.Key] = value.Value;
        }
Ejemplo n.º 4
0
        public void Add(LanguageDefinition languageDefinition)
        {
            if (_definition == null)
            {
                _definition = languageDefinition;
                return;
            }

            _definition.Contexts.AddRange(languageDefinition.Contexts);
            foreach (var value in languageDefinition.Values)
            {
                _definition.Values[value.Key] = value.Value;
            }
        }
Ejemplo n.º 5
0
 internal LocalizedStringBuilder(LanguageDefinition definition, string key, int amount)
     : this(definition, key)
 {
     _amount = amount;
     _parameters.Add(amount);
 }
Ejemplo n.º 6
0
 internal LocalizedStringBuilder(LanguageDefinition definition, string key, int amount)
     : this(definition, key)
 {
     _amount = amount;
     _parameters.Add(amount);
 }
Ejemplo n.º 7
0
        private static void HardcodedSample()
        {
            var commentValues = new List<LocalizedStringDefinition>
            {
                new LocalizedStringDefinition("WAT", null, -1),
                new LocalizedStringDefinition("No comments", 0, 0),
                new LocalizedStringDefinition("One comment", 1, 1),
                new LocalizedStringDefinition("{0} comments", 2)
            };

            var priceValues = new List<LocalizedStringDefinition>
            {
                new LocalizedStringDefinition("Free", null, 0),
                new LocalizedStringDefinition("Price: {0:C}", 1)
            };

            var values = new Dictionary<string, List<LocalizedStringDefinition>>
            {
                {"comments", commentValues},
                {"price", priceValues}
            };

            var maleProfileValues = new List<LocalizedStringDefinition>
            {
                new LocalizedStringDefinition("{0} updated his profile")
            };

            var femaleProfileValues = new List<LocalizedStringDefinition>
            {
                new LocalizedStringDefinition("{0} updated her profile")
            };

            var maleContext = new LocalizedValuesContext(new Dictionary<string, string> {{"gender", "male"}},
                new Dictionary<string, List<LocalizedStringDefinition>> {{"profileUpdate", maleProfileValues}});

            var femaleContext = new LocalizedValuesContext(new Dictionary<string, string> {{"gender", "female"}},
                new Dictionary<string, List<LocalizedStringDefinition>> {{"profileUpdate", femaleProfileValues}});

            var definition = new LanguageDefinition
            {
                Values = values,
                Contexts = new List<LocalizedValuesContext> {maleContext, femaleContext}
            };

            var m = new LocalizedStringProvider(definition);

            Console.WriteLine(m.Localize("comments").Plural(-1).WithParameters(-1).ToString());
            Console.WriteLine(m.Localize("comments").Plural(0).WithParameters(0).ToString());
            Console.WriteLine(m.Localize("comments").Plural(1).WithParameters(1).ToString());
            Console.WriteLine(m.Localize("comments").Plural(2).WithParameters(2).ToString());

            Console.WriteLine(m.Localize("profileUpdate").WithContext("gender", "male").WithParameters("Phil").ToString());
            Console.WriteLine(m.Localize("profileUpdate").WithContext("gender", "female").WithParameters("Lana"));

            string s = m.Localize("price", 0).WithParameters(0);
            string x = m.Localize("price", 10);

            Console.WriteLine($"{s}\n{x}");

            Console.ReadLine();
        }
Ejemplo n.º 8
0
 public LocalizedStringProvider(LanguageDefinition languageDefinition)
 {
     _definition = languageDefinition;
 }
Ejemplo n.º 9
0
 public LocalizedStringProvider(LanguageDefinition languageDefinition)
 {
     _definition = languageDefinition;
 }