Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/go-i18n.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicksnyder <nickdsnyder@gmail.com>2014-03-04 11:24:07 +0400
committernicksnyder <nickdsnyder@gmail.com>2014-03-04 11:24:07 +0400
commitdfb0a4ab72c2580699bfd9260c433748c33b664e (patch)
treee66b4c928c659abf20ce200938f54fa678417e06
parentbad5380b8c36381759a9e958c6f059481c7843c4 (diff)
Create gh-pages branch via GitHub
-rw-r--r--index.html15
-rw-r--r--params.json2
2 files changed, 7 insertions, 10 deletions
diff --git a/index.html b/index.html
index 4632d47..c844653 100644
--- a/index.html
+++ b/index.html
@@ -130,14 +130,14 @@ It accepts multiple locale parameters so you can gracefully fallback to other lo
<span class="p">})</span>
</pre></div>
-<p>A complete example is <a href="i18n/example_test.go">here</a>.</p>
+<p>A complete example is <a href="https://github.com/nicksnyder/go-i18n/blob/master/i18n/example_test.go">here</a>.</p>
<h5>
<a name="strings-in-templates" class="anchor" href="#strings-in-templates"><span class="octicon octicon-link"></span></a>Strings in templates</h5>
<p>You can call the <code>.Funcs()</code> method on a <a href="http://golang.org/pkg/text/template/#Template.Funcs">text/template</a> or <a href="http://golang.org/pkg/html/template/#Template.Funcs">html/template</a> to register the translation function for usage inside of that template.</p>
-<p>A complete example is <a href="i18n/exampletemplate_test.go">here</a>.</p>
+<p>A complete example is <a href="https://github.com/nicksnyder/go-i18n/blob/master/i18n/exampletemplate_test.go">here</a>.</p>
<h2>
<a name="goi18n-command" class="anchor" href="#goi18n-command"><span class="octicon octicon-link"></span></a>goi18n command</h2>
@@ -267,7 +267,7 @@ goi18n -help
<ol>
<li>Lookup the language's <a href="http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html">CLDR plural rules</a>.</li>
<li>
-<p>Add the language to <a href="i18n/language/language.go">language.go</a>:</p>
+<p>Add the language to <a href="https://github.com/nicksnyder/go-i18n/blob/master/i18n/language/language.go">language.go</a>:</p>
<div class="highlight highlight-go"><pre><span class="kd">var</span> <span class="nx">languages</span> <span class="p">=</span> <span class="kd">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="o">*</span><span class="nx">Language</span><span class="p">{</span>
<span class="c1">// ...</span>
@@ -275,21 +275,18 @@ goi18n -help
<span class="nx">ID</span><span class="p">:</span> <span class="s">"en"</span><span class="p">,</span>
<span class="nx">Name</span><span class="p">:</span> <span class="s">"English"</span><span class="p">,</span>
<span class="nx">PluralCategories</span><span class="p">:</span> <span class="nx">newSet</span><span class="p">(</span><span class="nx">plural</span><span class="p">.</span><span class="nx">One</span><span class="p">,</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Other</span><span class="p">),</span>
- <span class="nx">IntFunc</span><span class="p">:</span> <span class="kd">func</span><span class="p">(</span><span class="nx">i</span> <span class="kt">int64</span><span class="p">)</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Category</span> <span class="p">{</span>
- <span class="k">if</span> <span class="nx">i</span> <span class="o">==</span> <span class="mi">1</span> <span class="p">{</span>
+ <span class="nx">PluralFunc</span><span class="p">:</span> <span class="kd">func</span><span class="p">(</span><span class="nx">ops</span> <span class="o">*</span><span class="nx">plural</span><span class="p">.</span><span class="nx">Operands</span><span class="p">)</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Category</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="nx">ops</span><span class="p">.</span><span class="nx">I</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">&amp;&amp;</span> <span class="nx">ops</span><span class="p">.</span><span class="nx">V</span> <span class="o">==</span> <span class="mi">0</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">One</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Other</span>
<span class="p">},</span>
- <span class="nx">FloatFunc</span><span class="p">:</span> <span class="kd">func</span><span class="p">(</span><span class="nx">f</span> <span class="kt">float64</span><span class="p">)</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Category</span> <span class="p">{</span>
- <span class="k">return</span> <span class="nx">plural</span><span class="p">.</span><span class="nx">Other</span>
- <span class="p">},</span>
<span class="p">},</span>
<span class="c1">// ...</span>
<span class="p">}</span>
</pre></div>
</li>
-<li><p>Add a test to <a href="i18n/language/language_test.go">language_test.go</a></p></li>
+<li><p>Add a test to <a href="https://github.com/nicksnyder/go-i18n/blob/master/i18n/language/language_test.go">language_test.go</a></p></li>
<li>Submit a pull request!</li>
</ol><h2>
<a name="license" class="anchor" href="#license"><span class="octicon octicon-link"></span></a>License</h2>
diff --git a/params.json b/params.json
index e0a1faf..068e548 100644
--- a/params.json
+++ b/params.json
@@ -1 +1 @@
-{"name":"go-i18n","tagline":"Translate your Go program into multiple languages with templates and CLDR plural support.","body":"go-i18n [![Build Status](https://secure.travis-ci.org/nicksnyder/go-i18n.png?branch=master)](http://travis-ci.org/nicksnyder/go-i18n)\r\n=======\r\n\r\ngo-i18n is a Go [package](#i18n-package) and a [command](#goi18n-command) that can be used to translate Go programs into multiple lanaguages.\r\n\r\nRequires Go 1.2.\r\n\r\nFeatures\r\n--------\r\n\r\n* Implements [CLDR plural rules](http://cldr.unicode.org/index/cldr-spec/plural-rules).\r\n* Uses [text/template](http://golang.org/pkg/text/template/) for strings with variables.\r\n* Translation files are simple JSON.\r\n* [Documented](http://godoc.org/github.com/nicksnyder/go-i18n) and [tested](https://travis-ci.org/nicksnyder/go-i18n)!\r\n\r\ni18n package\r\n------------\r\n\r\nThe i18n package provides runtime APIs for looking up translated strings.\r\n\r\n```go\r\nimport \"github.com/nicksnyder/go-i18n/i18n\"\r\n```\r\n\r\n##### Loading translations\r\n\r\nLoad translation files during your program's initialization.\r\nThe name of a translation file must contain a supported [language tag](http://en.wikipedia.org/wiki/IETF_language_tag).\r\n\r\n```go\r\ni18n.MustLoadTranslationFile(\"path/to/fr-FR.all.json\")\r\n```\r\n\r\n##### Selecting a locale\r\n\r\nTfunc returns a function that can lookup the translation of a string for that locale.\r\nIt accepts multiple locale parameters so you can gracefully fallback to other locales.\r\n\r\n```go\r\nuserLocale = \"ar-AR\" // user preference, accept header, language cookie\r\ndefaultLocale = \"en-US\" // known valid locale\r\nT, err := i18n.Tfunc(userLocale, defaultLocale)\r\n```\r\n\r\n##### Loading a string translation\r\n\r\nUse the translation function to fetch the translation of a string.\r\n\r\n```go\r\nfmt.Println(T(\"Hello world\"))\r\n```\r\n\r\nUsually it is a good idea to identify strings by a generic id rather than the English translation, but the rest of this document will continue to use the English translation for readability.\r\n\r\n```go\r\nT(\"program_greeting\")\r\n```\r\n\r\n##### Strings with variables\r\n\r\nYou can have variables in your string using [text/template](http://golang.org/pkg/text/template/) syntax.\r\n\r\n```go\r\nT(\"Hello {{.Person}}\", map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n})\r\n```\r\n\r\n##### Plural strings\r\n\r\nEach language handles pluralization differently. A few examples:\r\n* English treats one as singular and all other numbers as plural (e.g. 0 cats, 1 cat, 2 cats).\r\n* French treats zero as singular.\r\n* Japan has a single plural form for all numbers.\r\n* Arabic has six different plural forms!\r\n\r\nThe translation function handles [all of this logic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html) for you.\r\n\r\n```go\r\nT(\"You have {{.Count}} unread emails\", 2)\r\nT(\"I am {{.Count}} meters tall.\", \"1.7\")\r\n```\r\n\r\nWith variables:\r\n\r\n```go\r\nT(\"{{.Person}} has {{.Count}} unread emails\", 2, map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n})\r\n```\r\n\r\nSentences with multiple plural components can be supported with nesting.\r\n\r\n```go\r\nT(\"{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}.\", 3, map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n\t\"Timeframe\": T(\"{{.Count}} days\", 2),\r\n})\r\n```\r\n\r\nA complete example is [here](i18n/example_test.go).\r\n\r\n##### Strings in templates\r\n\r\nYou can call the `.Funcs()` method on a [text/template](http://golang.org/pkg/text/template/#Template.Funcs) or [html/template](http://golang.org/pkg/html/template/#Template.Funcs) to register the translation function for usage inside of that template.\r\n\r\nA complete example is [here](i18n/exampletemplate_test.go).\r\n\r\ngoi18n command\r\n--------------\r\n\r\nThe goi18n command provides functionality for managing the translation process.\r\n\r\n### Installation\r\n\r\nMake sure you have [setup GOPATH](http://golang.org/doc/code.html#GOPATH).\r\n\r\n go get -u github.com/nicksnyder/go-i18n/goi18n\r\n goi18n -help\r\n\r\n### Workflow\r\n\r\nA typical workflow looks like this:\r\n\r\n1. Add a new string to your source code.\r\n\r\n ```go\r\n T(\"settings_title\")\r\n ```\r\n\r\n2. Add the string to en-US.all.json\r\n\r\n ```json\r\n [\r\n {\r\n \"id\": \"settings_title\",\r\n \"translation\": \"Settings\"\r\n }\r\n ]\r\n ```\r\n\r\n3. Run goi18n\r\n\r\n ```\r\n goi18n path/to/*.all.json\r\n ```\r\n\r\n4. Send `path/to/*.untranslated.json` to get translated.\r\n5. Run goi18n again to merge the translations\r\n\r\n ```sh\r\n goi18n path/to/*.all.json path/to/*.untranslated.json\r\n ```\r\n\r\nTranslation files\r\n-----------------\r\n\r\nA translation file stores translated and untranslated strings.\r\n\r\nExample:\r\n\r\n```json\r\n[\r\n {\r\n \"id\": \"d_days\",\r\n \"translation\": {\r\n \"one\": \"{{.Count}} day\",\r\n \"other\": \"{{.Count}} days\"\r\n }\r\n },\r\n {\r\n \"id\": \"my_height_in_meters\",\r\n \"translation\": {\r\n \"one\": \"I am {{.Count}} meter tall.\",\r\n \"other\": \"I am {{.Count}} meters tall.\"\r\n }\r\n },\r\n {\r\n \"id\": \"person_greeting\",\r\n \"translation\": \"Hello {{.Person}}\"\r\n },\r\n {\r\n \"id\": \"person_unread_email_count\",\r\n \"translation\": {\r\n \"one\": \"{{.Person}} has {{.Count}} unread email.\",\r\n \"other\": \"{{.Person}} has {{.Count}} unread emails.\"\r\n }\r\n },\r\n {\r\n \"id\": \"person_unread_email_count_timeframe\",\r\n \"translation\": {\r\n \"one\": \"{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.\",\r\n \"other\": \"{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}.\"\r\n }\r\n },\r\n {\r\n \"id\": \"program_greeting\",\r\n \"translation\": \"Hello world\"\r\n },\r\n {\r\n \"id\": \"your_unread_email_count\",\r\n \"translation\": {\r\n \"one\": \"You have {{.Count}} unread email.\",\r\n \"other\": \"You have {{.Count}} unread emails.\"\r\n }\r\n }\r\n]\r\n```\r\n\r\nSupported languages\r\n-------------------\r\n\r\n* Arabic (`ar`)\r\n* Catalan (`ca`)\r\n* Chinese (Simplified) (`zh-Hans`)\r\n* Chinese (Traditional) (`zh-Hant`)\r\n* Czech (`cs`)\r\n* Danish (`da`)\r\n* Dutch (`nl`)\r\n* English (`en`)\r\n* French (`fr`)\r\n* German (`de`)\r\n* Italian (`it`)\r\n* Japanese (`ja`)\r\n* Portuguese (`pt`)\r\n* Portuguese (Brazilian) (`pt-BR`)\r\n* Spanish (`es`)\r\n\r\nMore languages are straightforward to add:\r\n\r\n1. Lookup the language's [CLDR plural rules](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html).\r\n2. Add the language to [language.go](i18n/language/language.go):\r\n\r\n ```go\r\n var languages = map[string]*Language{\r\n // ...\r\n \"en\": &Language{\r\n ID: \"en\",\r\n Name: \"English\",\r\n PluralCategories: newSet(plural.One, plural.Other),\r\n IntFunc: func(i int64) plural.Category {\r\n if i == 1 {\r\n return plural.One\r\n }\r\n return plural.Other\r\n },\r\n FloatFunc: func(f float64) plural.Category {\r\n return plural.Other\r\n },\r\n },\r\n // ...\r\n }\r\n ```\r\n\r\n3. Add a test to [language_test.go](i18n/language/language_test.go)\r\n4. Submit a pull request!\r\n\r\nLicense\r\n-------\r\ngo-i18n is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\r\n","google":"UA-47572933-1","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file
+{"name":"go-i18n","tagline":"Translate your Go program into multiple languages with templates and CLDR plural support.","body":"go-i18n [![Build Status](https://secure.travis-ci.org/nicksnyder/go-i18n.png?branch=master)](http://travis-ci.org/nicksnyder/go-i18n)\r\n=======\r\n\r\ngo-i18n is a Go [package](#i18n-package) and a [command](#goi18n-command) that can be used to translate Go programs into multiple lanaguages.\r\n\r\nRequires Go 1.2.\r\n\r\nFeatures\r\n--------\r\n\r\n* Implements [CLDR plural rules](http://cldr.unicode.org/index/cldr-spec/plural-rules).\r\n* Uses [text/template](http://golang.org/pkg/text/template/) for strings with variables.\r\n* Translation files are simple JSON.\r\n* [Documented](http://godoc.org/github.com/nicksnyder/go-i18n) and [tested](https://travis-ci.org/nicksnyder/go-i18n)!\r\n\r\ni18n package\r\n------------\r\n\r\nThe i18n package provides runtime APIs for looking up translated strings.\r\n\r\n```go\r\nimport \"github.com/nicksnyder/go-i18n/i18n\"\r\n```\r\n\r\n##### Loading translations\r\n\r\nLoad translation files during your program's initialization.\r\nThe name of a translation file must contain a supported [language tag](http://en.wikipedia.org/wiki/IETF_language_tag).\r\n\r\n```go\r\ni18n.MustLoadTranslationFile(\"path/to/fr-FR.all.json\")\r\n```\r\n\r\n##### Selecting a locale\r\n\r\nTfunc returns a function that can lookup the translation of a string for that locale.\r\nIt accepts multiple locale parameters so you can gracefully fallback to other locales.\r\n\r\n```go\r\nuserLocale = \"ar-AR\" // user preference, accept header, language cookie\r\ndefaultLocale = \"en-US\" // known valid locale\r\nT, err := i18n.Tfunc(userLocale, defaultLocale)\r\n```\r\n\r\n##### Loading a string translation\r\n\r\nUse the translation function to fetch the translation of a string.\r\n\r\n```go\r\nfmt.Println(T(\"Hello world\"))\r\n```\r\n\r\nUsually it is a good idea to identify strings by a generic id rather than the English translation, but the rest of this document will continue to use the English translation for readability.\r\n\r\n```go\r\nT(\"program_greeting\")\r\n```\r\n\r\n##### Strings with variables\r\n\r\nYou can have variables in your string using [text/template](http://golang.org/pkg/text/template/) syntax.\r\n\r\n```go\r\nT(\"Hello {{.Person}}\", map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n})\r\n```\r\n\r\n##### Plural strings\r\n\r\nEach language handles pluralization differently. A few examples:\r\n* English treats one as singular and all other numbers as plural (e.g. 0 cats, 1 cat, 2 cats).\r\n* French treats zero as singular.\r\n* Japan has a single plural form for all numbers.\r\n* Arabic has six different plural forms!\r\n\r\nThe translation function handles [all of this logic](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html) for you.\r\n\r\n```go\r\nT(\"You have {{.Count}} unread emails\", 2)\r\nT(\"I am {{.Count}} meters tall.\", \"1.7\")\r\n```\r\n\r\nWith variables:\r\n\r\n```go\r\nT(\"{{.Person}} has {{.Count}} unread emails\", 2, map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n})\r\n```\r\n\r\nSentences with multiple plural components can be supported with nesting.\r\n\r\n```go\r\nT(\"{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}.\", 3, map[string]interface{}{\r\n\t\"Person\": \"Bob\",\r\n\t\"Timeframe\": T(\"{{.Count}} days\", 2),\r\n})\r\n```\r\n\r\nA complete example is [here](https://github.com/nicksnyder/go-i18n/blob/master/i18n/example_test.go).\r\n\r\n##### Strings in templates\r\n\r\nYou can call the `.Funcs()` method on a [text/template](http://golang.org/pkg/text/template/#Template.Funcs) or [html/template](http://golang.org/pkg/html/template/#Template.Funcs) to register the translation function for usage inside of that template.\r\n\r\nA complete example is [here](https://github.com/nicksnyder/go-i18n/blob/master/i18n/exampletemplate_test.go).\r\n\r\ngoi18n command\r\n--------------\r\n\r\nThe goi18n command provides functionality for managing the translation process.\r\n\r\n### Installation\r\n\r\nMake sure you have [setup GOPATH](http://golang.org/doc/code.html#GOPATH).\r\n\r\n go get -u github.com/nicksnyder/go-i18n/goi18n\r\n goi18n -help\r\n\r\n### Workflow\r\n\r\nA typical workflow looks like this:\r\n\r\n1. Add a new string to your source code.\r\n\r\n ```go\r\n T(\"settings_title\")\r\n ```\r\n\r\n2. Add the string to en-US.all.json\r\n\r\n ```json\r\n [\r\n {\r\n \"id\": \"settings_title\",\r\n \"translation\": \"Settings\"\r\n }\r\n ]\r\n ```\r\n\r\n3. Run goi18n\r\n\r\n ```\r\n goi18n path/to/*.all.json\r\n ```\r\n\r\n4. Send `path/to/*.untranslated.json` to get translated.\r\n5. Run goi18n again to merge the translations\r\n\r\n ```sh\r\n goi18n path/to/*.all.json path/to/*.untranslated.json\r\n ```\r\n\r\nTranslation files\r\n-----------------\r\n\r\nA translation file stores translated and untranslated strings.\r\n\r\nExample:\r\n\r\n```json\r\n[\r\n {\r\n \"id\": \"d_days\",\r\n \"translation\": {\r\n \"one\": \"{{.Count}} day\",\r\n \"other\": \"{{.Count}} days\"\r\n }\r\n },\r\n {\r\n \"id\": \"my_height_in_meters\",\r\n \"translation\": {\r\n \"one\": \"I am {{.Count}} meter tall.\",\r\n \"other\": \"I am {{.Count}} meters tall.\"\r\n }\r\n },\r\n {\r\n \"id\": \"person_greeting\",\r\n \"translation\": \"Hello {{.Person}}\"\r\n },\r\n {\r\n \"id\": \"person_unread_email_count\",\r\n \"translation\": {\r\n \"one\": \"{{.Person}} has {{.Count}} unread email.\",\r\n \"other\": \"{{.Person}} has {{.Count}} unread emails.\"\r\n }\r\n },\r\n {\r\n \"id\": \"person_unread_email_count_timeframe\",\r\n \"translation\": {\r\n \"one\": \"{{.Person}} has {{.Count}} unread email in the past {{.Timeframe}}.\",\r\n \"other\": \"{{.Person}} has {{.Count}} unread emails in the past {{.Timeframe}}.\"\r\n }\r\n },\r\n {\r\n \"id\": \"program_greeting\",\r\n \"translation\": \"Hello world\"\r\n },\r\n {\r\n \"id\": \"your_unread_email_count\",\r\n \"translation\": {\r\n \"one\": \"You have {{.Count}} unread email.\",\r\n \"other\": \"You have {{.Count}} unread emails.\"\r\n }\r\n }\r\n]\r\n```\r\n\r\nSupported languages\r\n-------------------\r\n\r\n* Arabic (`ar`)\r\n* Catalan (`ca`)\r\n* Chinese (Simplified) (`zh-Hans`)\r\n* Chinese (Traditional) (`zh-Hant`)\r\n* Czech (`cs`)\r\n* Danish (`da`)\r\n* Dutch (`nl`)\r\n* English (`en`)\r\n* French (`fr`)\r\n* German (`de`)\r\n* Italian (`it`)\r\n* Japanese (`ja`)\r\n* Portuguese (`pt`)\r\n* Portuguese (Brazilian) (`pt-BR`)\r\n* Spanish (`es`)\r\n\r\nMore languages are straightforward to add:\r\n\r\n1. Lookup the language's [CLDR plural rules](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html).\r\n2. Add the language to [language.go](https://github.com/nicksnyder/go-i18n/blob/master/i18n/language/language.go):\r\n\r\n ```go\r\n var languages = map[string]*Language{\r\n // ...\r\n \"en\": &Language{\r\n ID: \"en\",\r\n Name: \"English\",\r\n PluralCategories: newSet(plural.One, plural.Other),\r\n PluralFunc: func(ops *plural.Operands) plural.Category {\r\n if ops.I == 1 && ops.V == 0 {\r\n return plural.One\r\n }\r\n return plural.Other\r\n },\r\n },\r\n // ...\r\n }\r\n ```\r\n\r\n3. Add a test to [language_test.go](https://github.com/nicksnyder/go-i18n/blob/master/i18n/language/language_test.go)\r\n4. Submit a pull request!\r\n\r\nLicense\r\n-------\r\ngo-i18n is available under the MIT license. See the [LICENSE](LICENSE) file for more info.","google":"UA-47572933-1","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file