コード例 #1
0
        public static void Main(string[] args)
        {
            #region Snippet
            // Create asset
            var source = new Dictionary<string, string> { { "Culture:en:Key:hello", "Hello World!" } };
            IAsset asset = new StringAsset(source, LineFormat.Parameters);

            // Cache it
            asset = asset.CreateCache();

            // Issue a request which will be cached.
            ILine key = new LineRoot().Key("hello");
            IString value = asset.GetLine( key.Culture("en") ).GetString();
            Console.WriteLine(value);

            // Clear cache
            asset.Reload();
            #endregion Snippet
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_0a
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "en/MyController/Hello", "Hello World!" }
                };
                // Create key name policy
                ILineFormat policy =
                    new LineParameterPrinter()
                    .ParameterInfo(ParameterInfos.Default.Comparables(), prefixSeparator: "/") // Sorts parameters
                    .DefaultRule(true, prefixSeparator: "/");                                  // Default separator
                // Create asset
                IAsset asset = new StringAsset(source, policy);
                // Create key
                ILine key = new LineRoot(asset).Section("MyController").Key("Hello");
                // Retrieve string
                string str = key.Culture("en").ResolveString();
                #endregion Snippet_0a

                #region Snippet_0b
                // Test if key converted correctly to expected identity "en/Section/Key"
                string id = policy.Print(key.Culture("en"));
                #endregion Snippet_0b
            }

            {
                #region Snippet_1
                // Let's create an example key
                ILine key = new LineRoot()
                            .Location("Patches")
                            .Type("MyController")
                            .Section("Errors")
                            .Key("InvalidState")
                            .Culture("en");
                #endregion Snippet_1

                {
                    #region Snippet_2
                    // "en:Patches:MyController:Errors:InvalidState"
                    string str1 = LineParameterPrinter.Default.Print(key);
                    // "en.Patches.MyController.Errors.InvalidState"
                    string str2 = LineParameterPrinter.Dot_Dot_Dot.Print(key);
                    // "Patches:MyController:Errors:InvalidState"
                    string str3 = LineParameterPrinter.None_Colon_Colon.Print(key);
                    // "en:Patches.MyController.Errors.InvalidState"
                    string str4 = LineParameterPrinter.Colon_Dot_Dot.Print(key);
                    #endregion Snippet_2
                }

                {
                    #region Snippet_3
                    // Create a custom policy
                    ILineFormat myPolicy = new LineParameterPrinter()
                                           // Enable non-canonical "Culture" parameter with "/" separator
                                           .Rule("Culture", true, "", "/")
                                           // Disable other non-canonical parts
                                           .NonCanonicalRule(false)
                                           // Enable canonical all parts with "/" separator
                                           .CanonicalRule(true, "/", "")
                                           // Set "Key" parameter's prefix to "/" and postfix to ".txt".
                                           .Rule("Key", true, "/", ".txt");

                    // "en/Patches/MyController/Errors/InvalidState.txt"
                    string str = myPolicy.Print(key);
                    #endregion Snippet_3
                }

                {
                    #region Snippet_4
                    // Create similiar policy with LinePattern
                    ILineFormat myPolicy = new LinePattern("{culture/}{location/}{type/}{section/}[Key].txt");
                    // "en/Patches/MyController/Errors/InvalidState.txt"
                    string str = myPolicy.Print(key);
                    #endregion Snippet_4
                }

                {
                    #region Snippet_4a
                    // Create name pattern
                    ILineFormat myPolicy = new LinePattern("Patches/{Section}[-key]{-culture}.png");
                    #endregion Snippet_4a
                    // "Patches/icons-ok-de.png"
                    string str = myPolicy.Print(key);
                }
                {
                    #region Snippet_4b
                    // Create name pattern
                    ILineFormat myPolicy = new LinePattern("{location_0/}{location_1/}{location_n/}{Section}{-key}{-culture}.png");
                    // Create key
                    ILine key2 = new LineRoot().Location("Patches").Location("20181130").Section("icons").Key("ok").Culture("de");
                    // Converts to "Patches/20181130/icons-ok-de.png"
                    string str = myPolicy.Print(key2);
                    #endregion Snippet_4b
                }
                {
                    #region Snippet_4c
                    // Create name pattern with regular expression detail
                    ILinePattern myPolicy = new LinePattern("{location<[^/]+>/}{Section}{-key}{-culture}.png");
                    // Use its regular expression
                    Match match = myPolicy.Regex.Match("patches/icons-ok-de.png");
                    #endregion Snippet_4c
                }
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_0a
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "en/MyController/Hello", "Hello World!" }
                };
                // Create key name policy
                ILineFormat policy =
                    new LineParameterPrinter()
                    .ParameterInfo(ParameterInfos.Default.Comparables(), prefixSeparator: "/") // Sorts parameters
                    .DefaultRule(true, prefixSeparator: "/");                                  // Default separator
                // Create asset
                IAsset asset = new StringAsset(source, policy);
                // Create key
                ILine key = new LineRoot(asset).Section("MyController").Key("Hello");
                // Retrieve string
                string str = key.Culture("en").ResolveString();
                #endregion Snippet_0a

                #region Snippet_0b
                // Test if key converted correctly to expected identity "en/Section/Key"
                string id = policy.Print(key.Culture("en"));
                #endregion Snippet_0b
            }

            {
                #region Snippet_1
                // Let's create an example key
                ILine key = LineAppender.NonResolving
                            .Location("Patches")
                            .Section("Controllers")
                            .Type("MyController")
                            .Section("Errors")
                            .Key("InvalidState")
                            .Culture("en");
                #endregion Snippet_1

                {
                    #region Snippet_2
                    // "en:Patches:Controllers:MyController:Errors:InvalidState"
                    string str1 = LineParameterPrinter.Default.Print(key);
                    // "en.Patches.Controllers.MyController.Errors.InvalidState"
                    string str2 = LineParameterPrinter.Dot_Dot_Dot.Print(key);
                    // "Patches:Controllers:MyController:Errors:InvalidState"
                    string str3 = LineParameterPrinter.None_Colon_Colon.Print(key);
                    // "en:Patches.Controllers.MyController.Errors.InvalidState"
                    string str4 = LineParameterPrinter.Colon_Dot_Dot.Print(key);
                    // "en:Patches:Controllers:MyController:Errors.InvalidState"
                    string str5 = LineParameterPrinter.Colon_Colon_Dot.Print(key);
                    #endregion Snippet_2
                }

                {
                    #region Snippet_3
                    // Create a custom policy
                    ILineFormat myPolicy = new LineParameterPrinter()
                                           // Enable non-canonical "Culture" parameter with "/" separator
                                           .Rule("Culture", true, postfixSeparator: "/", order: ParameterInfos.Default.GetValue("Culture").Order)
                                           // Disable other non-canonical parts
                                           .NonCanonicalRule(false)
                                           // Enable canonical all parts with "/" separator
                                           .CanonicalRule(true, prefixSeparator: "/")
                                           // Set "Key" parameter's prefix to "/"
                                           .Rule("Key", true, prefixSeparator: "/", order: ParameterInfos.Default.GetValue("Key").Order);

                    // "en/Patches/MyController/Errors/InvalidState"
                    string str = myPolicy.Print(key);
                    #endregion Snippet_3
                }
            }
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_1a
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "MyController:hello", "Hello World!" },
                    { "en:MyController:hello", "Hello World!" },
                    { "de:MyController:hello", "Hallo Welt!" }
                };
                // Create asset with string source
                IAsset asset = new StringAsset().Add(source, "{Culture:}[Type:][Key]").Load();
                #endregion Snippet_1a
                ILine key = new LineRoot(asset).Type("MyController").Key("hello");
                Console.WriteLine(key);
                Console.WriteLine(key.Culture("en"));
                Console.WriteLine(key.Culture("de"));
            }

            {
                #region Snippet_1b
                // Create localization source
                var source = new List <ILine> {
                    { LineFormat.Parameters.Parse("Type:MyController:Key:hello").Format("Hello World!") },
                    { LineFormat.Parameters.Parse("Culture:en:Type:MyController:Key:hello").Format("Hello World!") },
                    { LineFormat.Parameters.Parse("Culture:de:Type:MyController:Key:hello").Format("Hallo Welt!") }
                };
                // Create asset with string source
                IAsset asset = new StringAsset().Add(source).Load();
                #endregion Snippet_1b

                #region Snippet_2b
                ILine key = new LineRoot(asset).Type("MyController").Key("hello");
                Console.WriteLine(key);
                Console.WriteLine(key.Culture("en"));
                Console.WriteLine(key.Culture("de"));
                #endregion Snippet_2b
            }

            {
                #region Snippet_1c
                // Create localization source
                var source = new Dictionary <ILine, string> {
                    { new LineRoot().Type("MyController").Key("hello"), "Hello World!" },
                    { new LineRoot().Type("MyController").Key("hello").Culture("en"), "Hello World!" },
                    { new LineRoot().Type("MyController").Key("hello").Culture("de"), "Hallo Welt!" }
                };
                // Create asset with string source
                IAsset asset = new StringAsset().Add(source).Load();
                #endregion Snippet_1c

                #region Snippet_2c
                ILine key = new LineRoot(asset).Type("MyController").Key("hello");
                Console.WriteLine(key);
                Console.WriteLine(key.Culture("en"));
                Console.WriteLine(key.Culture("de"));
                #endregion Snippet_2c
            }

            {
                var source = new Dictionary <string, string> {
                    { "MyController:hello", "Hello World!" },
                    { "en:MyController:hello", "Hello World!" },
                    { "de:MyController:hello", "Hallo Welt!" }
                };
                // Create asset with string source
                IAsset asset = new StringAsset().Add(source, "{Culture:}[Type:][Key]").Load();
                #region Snippet_3a
                // Extract all keys
                foreach (var _key in asset.GetStringLines(null))
                {
                    Console.WriteLine(_key);
                }
                #endregion Snippet_3a
            }
            {
                #region Snippet_3b
                var source = new List <ILine> {
                    LineAppender.Default.Type("MyController").Key("hello").Format("Hello World!"),
                    LineAppender.Default.Type("MyController").Key("hello").Culture("en").Format("Hello World!"),
                    LineAppender.Default.Type("MyController").Key("hello").Culture("de").Format("Hallo Welt!")
                };
                // Keys can be filtered
                ILine  filterKey = LineAppender.Default.Culture("de");
                IAsset asset     = new StringAsset().Add(source, "{Culture:}[Type:][Key]").Load();
                foreach (var _key in asset.GetLines(filterKey))
                {
                    Console.WriteLine(_key.Print(LineFormat.ParametersInclString));
                }
                #endregion Snippet_3b
            }
        }