Skip to content

Commit f746420

Browse files
author
Leonel Quinteros Carbano
committed
Add Github Build action badge
1 parent d26d707 commit f746420

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

README.md

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[![GitHub release](https://img.shields.io/github/release/leonelquinteros/gotext.svg)](https://github.com/leonelquinteros/gotext)
22
[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
33
[![GoDoc](https://godoc.org/github.com/leonelquinteros/gotext?status.svg)](https://godoc.org/github.com/leonelquinteros/gotext)
4+
![Gotext build](https://github.com/leonelquinteros/gotext/workflows/Gotext%20build/badge.svg?branch=master)
45
[![Build Status](https://travis-ci.org/leonelquinteros/gotext.svg?branch=master)](https://travis-ci.org/leonelquinteros/gotext)
56
[![Go Report Card](https://goreportcard.com/badge/github.com/leonelquinteros/gotext)](https://goreportcard.com/report/github.com/leonelquinteros/gotext)
67

78
# Gotext
89

9-
[GNU gettext utilities](https://www.gnu.org/software/gettext) for Go.
10+
[GNU gettext utilities](https://www.gnu.org/software/gettext) for Go.
1011

1112

1213
# Features
@@ -17,8 +18,8 @@
1718
- Support for variables inside translation strings using Go's [fmt syntax](https://golang.org/pkg/fmt/).
1819
- Support for [pluralization rules](https://www.gnu.org/software/gettext/manual/html_node/Translating-plural-forms.html).
1920
- Support for [message contexts](https://www.gnu.org/software/gettext/manual/html_node/Contexts.html).
20-
- Support for MO files.
21-
- Thread-safe: This package is safe for concurrent use across multiple goroutines.
21+
- Support for MO files.
22+
- Thread-safe: This package is safe for concurrent use across multiple goroutines.
2223
- It works with UTF-8 encoding as it's the default for Go language.
2324
- Unit tests available.
2425
- Language codes are automatically simplified from the form `en_UK` to `en` if the first isn't available.
@@ -37,15 +38,15 @@
3738
Refer to the Godoc package documentation at (https://godoc.org/github.com/leonelquinteros/gotext)
3839

3940

40-
# Installation
41+
# Installation
4142

4243
```
4344
go get github.com/leonelquinteros/gotext
4445
```
4546

46-
- There are no requirements or dependencies to use this package.
47+
- There are no requirements or dependencies to use this package.
4748
- No need to install GNU gettext utilities (unless specific needs of CLI tools).
48-
- No need for environment variables. Some naming conventions are applied but not needed.
49+
- No need for environment variables. Some naming conventions are applied but not needed.
4950

5051

5152
## Version vendoring
@@ -103,19 +104,19 @@ Refer to it as gotext.
103104

104105
# Locales directories structure
105106

106-
The package will assume a directories structure starting with a base path that will be provided to the package configuration
107-
or to object constructors depending on the use, but either will use the same convention to lookup inside the base path.
107+
The package will assume a directories structure starting with a base path that will be provided to the package configuration
108+
or to object constructors depending on the use, but either will use the same convention to lookup inside the base path.
108109

109-
Inside the base directory where will be the language directories named using the language and country 2-letter codes (en_US, es_AR, ...).
110-
All package functions can lookup after the simplified version for each language in case the full code isn't present but the more general language code exists.
111-
So if the language set is `en_UK`, but there is no directory named after that code and there is a directory named `en`,
112-
all package functions will be able to resolve this generalization and provide translations for the more general library.
110+
Inside the base directory where will be the language directories named using the language and country 2-letter codes (en_US, es_AR, ...).
111+
All package functions can lookup after the simplified version for each language in case the full code isn't present but the more general language code exists.
112+
So if the language set is `en_UK`, but there is no directory named after that code and there is a directory named `en`,
113+
all package functions will be able to resolve this generalization and provide translations for the more general library.
113114

114-
The language codes are assumed to be [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes (2-letter codes).
115+
The language codes are assumed to be [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes (2-letter codes).
115116
That said, most functions will work with any coding standard as long the directory name matches the language code set on the configuration.
116117

117-
Then, there can be a `LC_MESSAGES` containing all PO files or the PO files themselves.
118-
A library directory structure can look like:
118+
Then, there can be a `LC_MESSAGES` containing all PO files or the PO files themselves.
119+
A library directory structure can look like:
119120

120121
```
121122
/path/to/locales
@@ -140,7 +141,7 @@ A library directory structure can look like:
140141
/path/to/locales/fr
141142
/path/to/locales/fr/default.po
142143
/path/to/locales/fr/extras.po
143-
```
144+
```
144145

145146
And so on...
146147

@@ -160,10 +161,10 @@ import (
160161
func main() {
161162
// Configure package
162163
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
163-
164+
164165
// Translate text from default domain
165166
fmt.Println(gotext.Get("My text on 'domain-name' domain"))
166-
167+
167168
// Translate text from a different domain without reconfigure
168169
fmt.Println(gotext.GetD("domain2", "Another text on a different domain"))
169170
}
@@ -172,8 +173,8 @@ func main() {
172173

173174
## Using dynamic variables on translations
174175

175-
All translation strings support dynamic variables to be inserted without translate.
176-
Use the fmt.Printf syntax (from Go's "fmt" package) to specify how to print the non-translated variable inside the translation string.
176+
All translation strings support dynamic variables to be inserted without translate.
177+
Use the fmt.Printf syntax (from Go's "fmt" package) to specify how to print the non-translated variable inside the translation string.
177178

178179
```go
179180
import (
@@ -184,10 +185,10 @@ import (
184185
func main() {
185186
// Configure package
186187
gotext.Configure("/path/to/locales/root/dir", "en_UK", "domain-name")
187-
188+
188189
// Set variables
189190
name := "John"
190-
191+
191192
// Translate text with variables
192193
fmt.Println(gotext.Get("Hi, my name is %s", name))
193194
}
@@ -197,7 +198,7 @@ func main() {
197198

198199
## Using Locale object
199200

200-
When having multiple languages/domains/libraries at the same time, you can create Locale objects for each variation
201+
When having multiple languages/domains/libraries at the same time, you can create Locale objects for each variation
201202
so you can handle each settings on their own.
202203

203204
```go
@@ -209,23 +210,23 @@ import (
209210
func main() {
210211
// Create Locale with library path and language code
211212
l := gotext.NewLocale("/path/to/locales/root/dir", "es_UY")
212-
213+
213214
// Load domain '/path/to/locales/root/dir/es_UY/default.po'
214215
l.AddDomain("default")
215-
216+
216217
// Translate text from default domain
217218
fmt.Println(l.Get("Translate this"))
218-
219+
219220
// Load different domain
220221
l.AddDomain("translations")
221-
222+
222223
// Translate text from domain
223224
fmt.Println(l.GetD("translations", "Translate this"))
224225
}
225226
```
226227

227228
This is also helpful for using inside templates (from the "text/template" package), where you can pass the Locale object to the template.
228-
If you set the Locale object as "Loc" in the template, then the template code would look like:
229+
If you set the Locale object as "Loc" in the template, then the template code would look like:
229230

230231
```
231232
{{ .Loc.Get "Translate this" }}
@@ -234,7 +235,7 @@ If you set the Locale object as "Loc" in the template, then the template code wo
234235

235236
## Using the Po object to handle .po files and PO-formatted strings
236237

237-
For when you need to work with PO files and strings,
238+
For when you need to work with PO files and strings,
238239
you can directly use the Po object to parse it and access the translations in there in the same way.
239240

240241
```go
@@ -255,11 +256,11 @@ msgstr ""
255256
msgid "One with var: %s"
256257
msgstr "This one sets the var: %s"
257258
`
258-
259+
259260
// Create Po object
260261
po := new(gotext.Po)
261262
po.Parse(str)
262-
263+
263264
fmt.Println(po.Get("Translate this"))
264265
}
265266
```
@@ -299,21 +300,21 @@ msgid_plural "Several with vars: %s"
299300
msgstr[0] "This one is the singular: %s"
300301
msgstr[1] "This one is the plural: %s"
301302
`
302-
303+
303304
// Create Po object
304305
po := new(gotext.Po)
305306
po.Parse(str)
306-
307+
307308
fmt.Println(po.GetN("One with var: %s", "Several with vars: %s", 54, v))
308309
// "This one is the plural: Variable"
309310
}
310311
```
311312

312313

313-
# Contribute
314+
# Contribute
314315

315316
- Please, contribute.
316317
- Use the package on your projects.
317-
- Report issues on Github.
318+
- Report issues on Github.
318319
- Send pull requests for bugfixes and improvements.
319320
- Send proposals on Github issues.

0 commit comments

Comments
 (0)