Selaa lähdekoodia

Add more documentation

- Added file format examples.
- Updated README.
joeybloggs 8 vuotta sitten
vanhempi
commit
11180fc8a5

+ 31 - 1
README.md

@@ -26,7 +26,7 @@ Features
 - [x] Contains Number, Currency, Accounting and Percent formatting functions
 - [x] Supports the "Gregorian" calendar only ( my time isn't unlimited, had to draw the line somewhere )
 - [x] Support loading translations from files
-- [x] Exporting translations to file, mainly for getting them professionally translated
+- [x] Exporting translations to file(s), mainly for getting them professionally translated
 - [ ] Code Generation for translation files -> Go code.. i.e. after it has been professionally translated
 - [ ] Tests for all languages, I need help with this, please see [here](https://github.com/go-playground/locales/issues/1)
 
@@ -50,6 +50,36 @@ Please see https://godoc.org/github.com/go-playground/universal-translator for u
 - [Full - no files](https://github.com/go-playground/universal-translator/tree/master/examples/full-no-files)
 - [Full - with files](https://github.com/go-playground/universal-translator/tree/master/examples/full-with-files)
 
+File formatting
+--------------
+All types, Plain substitution, Cardinal, Ordinal and Range translations can all be contained withing the same file(s);
+they are only separated for easy viewing.
+
+##### Examples:
+
+- [Formats](https://github.com/go-playground/universal-translator/tree/master/examples/file-formats)
+
+##### Basic Makeup
+NOTE: not all fields are needed for all translation type, see [examples](https://github.com/go-playground/universal-translator/tree/master/examples/file-formats)
+```json
+{
+    "locale": "en",
+    "key": "days-left",
+    "trans": "You have {0} day left.",
+    "type": "Cardinal",
+    "rule": "One",
+    "override": false
+}
+```
+|Field|Description|
+|---|---|
+|locale|The locale for which the translation is for.|
+|key|The translation key that will be used to store and lookup each translation; normally it is a string or integer.|
+|trans|The actual translation text.|
+|type|The type of translation Cardinal, Ordinal, Range or "" for a plain substitution(not required to be defined in plain used)|
+|rule|The plural rule for which the translation is for eg. One, Two, Few, Many or Other.(not required to be defined in plain used)|
+|override|If you wish to override an existing translation that has already been registered, set this to 'true'. 99% of the time there is no need to define it.|
+
 Help With Tests
 ---------------
 To anyone interesting in helping or contributing, I sure could use some help creating tests for each language.

+ 16 - 0
examples/file-formats/cardinal.json

@@ -0,0 +1,16 @@
+[
+    {
+        "locale": "en",
+        "key": "cardinal_test",
+        "trans": "You have {0} day left.",
+        "type": "Cardinal",
+        "rule": "One"
+    },
+    {
+        "locale": "en",
+        "key": "cardinal_test",
+        "trans": "You have {0} days left.",
+        "type": "Cardinal",
+        "rule": "Other"
+    }
+]

+ 30 - 0
examples/file-formats/ordinal.json

@@ -0,0 +1,30 @@
+[
+    {
+        "locale": "en",
+        "key": "day",
+        "trans": "{0}st",
+        "type": "Ordinal",
+        "rule": "One"
+    },
+    {
+        "locale": "en",
+        "key": "day",
+        "trans": "{0}nd",
+        "type": "Ordinal",
+        "rule": "Two"
+    },
+    {
+        "locale": "en",
+        "key": "day",
+        "trans": "{0}rd",
+        "type": "Ordinal",
+        "rule": "Few"
+    },
+    {
+        "locale": "en",
+        "key": "day",
+        "trans": "{0}th",
+        "type": "Ordinal",
+        "rule": "Other"
+    }
+]

+ 27 - 0
examples/file-formats/plain-substitution.json

@@ -0,0 +1,27 @@
+[
+    {
+        "locale": "en",
+        "key": "test_trans4",
+        "trans": "{0}{1}"
+    },
+    {
+        "locale": "en",
+        "key": "test_trans",
+        "trans": "Welcome {0} to the {1}."
+    },
+    {
+        "locale": "en",
+        "key": -1,
+        "trans": "Welcome {0}"
+    },
+    {
+        "locale": "en",
+        "key": "test_trans2",
+        "trans": "{0} to the {1}."
+    },
+    {
+        "locale": "en",
+        "key": "test_trans3",
+        "trans": "Welcome {0} to the {1}"
+    }
+]

+ 16 - 0
examples/file-formats/range.json

@@ -0,0 +1,16 @@
+[
+    {
+        "locale": "nl",
+        "key": "day",
+        "trans": "er {0}-{1} dag vertrokken",
+        "type": "Range",
+        "rule": "One"
+    },
+    {
+        "locale": "nl",
+        "key": "day",
+        "trans": "er zijn {0}-{1} dagen over",
+        "type": "Range",
+        "rule": "Other"
+    }
+]