-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4510bf2
Showing
22 changed files
with
825 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Igor Afanasyev, https://github.com/iafan | ||
Richard Cooper <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# go-l10n - Localization for humans | ||
|
||
**english** [русский](https://github.com/xelaj/go-l10n/blob/master/doc/ru_RU/README.md) | ||
|
||
Quick and easy localization of your Go projects! | ||
|
||
This package is based on the [go-l10n package](https://github.com/iafan/go-l10n) created by | ||
[iafan](https://github.com/iafan). | ||
|
||
## Getting Started | ||
|
||
as simple as another packages: | ||
|
||
`go get github.com/xelaj/go-l10n` | ||
|
||
## how to use | ||
|
||
**code examples are [here](https://github.com/xelaj/go-l10n/examples/main.go)** | ||
|
||
The main struct you will use is `l10n.Pool`. on init func it takes filepath to | ||
locale dirs, the name of your application and the main language into which you will translate | ||
messages. | ||
|
||
messages are taken from the directory that you specify during initialization. however, it must have | ||
certain structure: | ||
|
||
``` | ||
locale | ||
en_US | ||
YourApp | ||
locale.json | ||
another folder | ||
locale.json | ||
third.json | ||
info.cfg | ||
ru_RU | ||
YourApp | ||
locale.json | ||
another folder | ||
locale.json | ||
third.json | ||
info.cfg | ||
ua_UA | ||
... | ||
es_ES | ||
... | ||
``` | ||
|
||
`info.cfg` is a summary of the locale. it is written to the l10n.Locale object. she keeps in | ||
The following parameters: | ||
|
||
```ini | ||
# name of language on ascii | ||
name = Russian | ||
|
||
# localized name of language | ||
translate = Russian | ||
|
||
# which language it extends. if you have unsupported locale name, package returns key name | ||
extends = | ||
``` | ||
|
||
all three parameters are optional. however, the file itself in each folder with the same name is required. | ||
|
||
`YourApp` essentially implements the namespaces of various applications. | ||
|
||
inside the directory of your application, you can do absolutely any structure of your files, | ||
the only important thing is that the names of the messages in all these files do not overlap. if that happens then | ||
The translation closest to the root directory will be selected. | ||
|
||
each locale file is a json file with the following parameters: | ||
|
||
``` json | ||
{ | ||
"about": { | ||
"message": "this is locale file!", | ||
"description": "use this description to message message" | ||
}, | ||
"hello text": { | ||
"message": "hello!" | ||
} | ||
} | ||
``` | ||
|
||
examples of file struvture can be seen [here](https://github.com/xelaj/go-l10n/examples/locale) | ||
|
||
## Contributing | ||
|
||
Please read [contributing guide](https://github.com/xelaj/go-l10n/doc/ru_RU/CONTRIBUTING.md) if you want to help. And the help is very necessary! | ||
|
||
## Authors | ||
|
||
* **Igor Afanasyev** — *base library* - [iafan](https://github.com/iafan) | ||
* **Richard Cooper** — *other stuff* - [ololosha228](https://github.com/ololosha228) | ||
|
||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/xelaj/go-l10n/doc/en_US/LICENSE) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package l10n | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/iafan/Plurr/go/plurr" | ||
) | ||
|
||
// Context holds a localization context | ||
// (a combination of a language, a corresponding Plurr formatter, | ||
// and a link back to parent localization Pool object) | ||
type Context struct { | ||
pool *Pool | ||
lang string | ||
plurr *plurr.Plurr | ||
} | ||
|
||
// GetLanguage returns the current language of the context. | ||
func (lc *Context) GetLang() string { | ||
return lc.lang | ||
} | ||
|
||
// Tr returns a translated version of the string | ||
func (lc *Context) Tr(key string) string { | ||
return lc.tr(key, lc.lang) | ||
} | ||
|
||
// Trf returns a formatted version of the string | ||
func (lc *Context) Trf(key string, params plurr.Params) (string, error) { | ||
s, err := lc.plurr.Format(lc.Tr(key), params) | ||
if err != nil { | ||
return "", errors.New(key + ": " + err.Error()) | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
func (lc *Context) Strf(key string, params plurr.Params) string { | ||
r, err := lc.Trf(key, params) | ||
if err != nil { | ||
return lc.Tr(key) | ||
} | ||
return r | ||
} | ||
|
||
func (lc *Context) tr(key, lang string) string { | ||
resource, ok := lc.pool.Resources[lang] | ||
if !ok { | ||
err := lc.pool.PreloadResource(lang) | ||
if err != nil { | ||
return key | ||
} | ||
|
||
resource = lc.pool.Resources[lang] | ||
} | ||
|
||
s, ok := resource[key] | ||
if ok { | ||
return s | ||
} | ||
return lc.trAlternate(key, lang) | ||
} | ||
|
||
func (lc *Context) trAlternate(key, lang string) string { | ||
info, err := langInfo(lc.pool.resourcePath, lang) | ||
if err != nil { | ||
return key | ||
} | ||
|
||
if info.Extends != "" { | ||
return lc.tr(key, info.Extends) | ||
} | ||
|
||
return key | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Behavior rules | ||
|
||
**english** [русский]((https://github.com/xelaj/go-l10n/blob/master/doc/ru_RU/CODE_OF_CONDUCT.md)) | ||
|
||
In order to organize an productive communication and development environment (rather than acidic and destructive), we want to tell you about the rules of behavior in our community. there is nothing out of the ordinary here, just to remind you how good girls and boys behave. | ||
|
||
## The first and most important rule | ||
|
||
0. Don't be shithole. No, this rule is most important. Do **not** be shithole, please. | ||
|
||
### Other rules | ||
|
||
1. Respect any point of view of other people. People are mostly not stupid, and want to help. Try to make a constructive and reasoned conversation with anyone. | ||
2. Chat with newbies kindly. This will help them to quickly roll into the community, so larger and friendlier the community is the better than small and acidic. | ||
3. Respect what we do. Nobody is against critic, but try to do something in general, not only to please yourself, but also to the community. | ||
4. Repeat rule #0 as a mantra. It is the most important | ||
|
||
### What not to do | ||
|
||
1. Trolling is not particularly appropriate. Even if the victim of your trolling is mentally retarded and does not know how to google. don't troll him, he is already swallowed: full_moon_with_face: | ||
2. People have feelings, don't forget about it! see rule #0. | ||
3. Don't forget about rule #0. You should never forget about it. | ||
|
||
## Rights and obligations of maintainers | ||
|
||
As organizers, we have our rights and responsibilities. | ||
|
||
We are obliged: | ||
1. Explain to each of these rules of conduct, and make sure that everyone in the community performs them <sub><sup><sub><sup>read as: do not shitholing</sup></sub></sup></sub> | ||
2. Reject any commits, comments, ischuses, pool requests, anything that contradicts these rules. | ||
3. Prevent any violations of these rules by the user, in the form of a ban, mute, or any other action that the platform allows. | ||
|
||
## Where do these rules apply | ||
|
||
In any community organized by the Xelaj team. In any chat rooms, repositories, groups, anywhere. In addition, these rules also apply to communities based on Xelaj communities. This means that if you represent our service, community, or simply even us as a team, you must adhere to these rules, as well as the rights and obligations of maintainers are imposed on you. | ||
|
||
## A little about the other | ||
By writing these rules, we followed [Contributor Covenant](https://contributor-covenant.org). This means that he, too, would be worth reading and generally sticking to this covenant. | ||
|
||
Consider also that some rules can be broken in general, but we are not beasts. But the main thing: **do not be shithole** and **wish the community for good**. Good is always good. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Contributing to go-l10n | ||
|
||
based on [Xelaj styleguides](https://github.com/xelaj/xelaj/birch/blob/master/CONTRIBUTING.md). | ||
|
||
**english** [русский](https://github.com/xelaj/go-l10n/blob/master/doc/ru_RU/CONTRIBUTING.md) | ||
|
||
:new_moon_with_face: :new_moon_with_face: First of all, thanks for your helping! :full_moon_with_face: :full_moon_with_face: | ||
|
||
This page briefly describes the process of developing both the specific go-l10n package and all Xelaj projects. if you read all these rules, you will be the best helper in the whole wild west! | ||
|
||
## Code of conduct | ||
|
||
We all want make other people happy! We believe that you are a good guy, but please, just in case, read our [code of conduct](https://github.com/xelaj/go-l10n/blob/master/doc/en_US/CODE_OF_CONDUCT.md). They will help you understand what ideals we adhere to, among other things, you will be even more cool! | ||
|
||
By joining our community, you automatically agree to our rules _(even if you have not read them!)_. and if you saw their violation somewhere, write to [email protected], we will help! | ||
|
||
## I don't want to read anything, I have a question! | ||
|
||
> **Just remind:** you just don’t need to ask anything right to issues, okay? just not necessary. you will quickly solve your problem if you find the answer below | ||
We have the official Xelaj chat in Telegram: [@xelaj_developers](http://t.me/xelaj_developers). In this chat you can promptly clarify the information of interest to you. | ||
|
||
And we also actually want to do [FAQ](https://github.com/xelaj/go-l10n/blob/master/doc/en_US/FAQ.md), but we don’t know what questions to write there, so , if you are reading this, probably write while in the Telegram, we'll figure it out :) | ||
|
||
## What do I need to know before I can help? | ||
|
||
`¯ \ _ (ツ) _ / ¯` | ||
|
||
## And how can I help? | ||
|
||
### For example, report a bug. | ||
|
||
#### before reporting a bug: | ||
|
||
* Look for issues with a bug / bug label, it is likely that it has already been reported. | ||
* **even if you found issue**: describe your situation in the comments of issue, attach logs, backup database, just do not duplicate issues. | ||
|
||
### You can still offer a new feature: | ||
|
||
We love to add new features! Use the New Feature issues template and fill in all the fields. Attaching labels is also very important! | ||
|
||
### and you can immediately offer a pull request! | ||
|
||
Here it is up to you, the only thing is: we are more willing to take pull requests based on a specific issue (i.e. created pull request based on issue #100500 or something like this) This will help us understand what problem your request solves. | ||
|
||
## Styleguides | ||
|
||
### commit comments | ||
|
||
* do not write what commits do (❌ — `commit adds ...` ✅ — `added support ...`) | ||
* do not write **who** made a commit (❌ — `I changed ...` ❌ — `our team worked for a long time and created ...`) | ||
* write briefly (no more than 60 characters), everything else - in the description after two (2) new lines | ||
* pour all your misery into the commit description, not the comment (❌ — `fool, forgot to delete ...` ✅ — `removed ...`) | ||
* use prefixes, damn it! in general, we love emoji, so attach emoji: | ||
* :art: `:art:` if you added a new method to the API. | ||
* :memo: `:memo:` if you added documentation (**pay attention!** if you write documentation for the commit you made, you do not need to make a separate commit with the documentation!) | ||
* :shirt: `:shirt:` if the build process was updated | ||
* :pill: `:pill:` minor updates, fixes in one letter in the documentation, etc. not affecting the operation of the code | ||
* :bug: `:bug:` bug fixes! | ||
* :lock: `:lock:` if this is a security bug | ||
* :twisted_rightwards_arrows: `:twisted_rightwards_arrows:` merge commits. any | ||
* :racehorse: `:racehorse:` refactoring code | ||
* :white_check_mark: `:white_check_mark:` work with tests | ||
* :fire: `:fire:` if you delete (irrevocably!) any part of the service: code, file, configs, whatever. | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2019, Richard Cooper <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Правила Поведения | ||
|
||
[english](https://github.com/xelaj/go-l10n/blob/master/doc/en_US/CODE_OF_CONDUCT.md) **русский** | ||
|
||
Для того что бы организовать адекватную среду общения и разработки (а не кислотную и деструктивную), мы хотим вам рассказать про правила поведения в нашем сообществе. здесь нет чего-то из ряда вон выходящего, просто хотим напомнить, как ведут себя хорошие девочки и мальчики. | ||
|
||
## Первое и самое главное правило | ||
|
||
0. Не быть говноедом. Нет правда, это правило важнее всего. Не будьте говноедами, пожалуйста. | ||
|
||
### Другие правила | ||
|
||
1. Уважайте точки зрения других людей. Люди по большей части не глупые, и желают помочь. Старайтесь вести конструктивную и аргументированную беседу с кем либо. | ||
2. Общайтесь с новичками доброжелательно. Это поможет им быстрее вкатиться в сообщество, а чем больше и дружнее сообщество — тем лучше | ||
3. Уважайте то, что мы делаем. Никто не против критики, но старайтесь в целом делать что либо не только в угоду себе, но и сообществу. | ||
4. Повторяйте правило #0 как мантру. Оно самое важное | ||
|
||
### Чего не стоит делать | ||
|
||
1. Троллинг у нас не особо уместен. Даже если жертва вашего троллинга умственно отсталая и не умеет гуглить. Не стоит ее троллить, уже нахлебалась :full_moon_with_face: | ||
2. У людей есть чувства, не стоит об этом забывать! см. правило #0. | ||
3. Не забывайте о правиле #0. О нем вообще нельзя никогда забывать | ||
|
||
## Права и обязанности мейнтейнеров | ||
|
||
Как организаторы, у нас есть свои права и обязанности | ||
|
||
Мы обязуемся: | ||
1. Объяснять каждому данные правила поведения, и следить, что бы каждый в сообществе их исполнял <sub><sup><sub><sup>читай: не говноедил</sup></sub></sup></sub> | ||
2. Отклонять любые коммиты, комментарии, ишьюзы, пул реквесты, что угодно, что противоречит данным правилам. | ||
3. Пресекать любые нарушения данных правил пользователем, в виде бана, мута, или любого другого действия, которое позволяет платформа. | ||
|
||
## Где применяются данные правила | ||
|
||
В любом сообществе организованном командой Xelaj. В любых чатах, репозиториях, группах, где угодно. Помимо этого, данные правила действуют и для тех сообществ, которые были основаны на сообществах Xelaj. Это означает, что если вы представляете наш сервис, сообщество, или просто даже нас как команду, вы обязаны придерживаться данных правил, а так же на вас накладываются права и обязанности мейнтейнеров. | ||
|
||
## Немножко о другом | ||
Писав данные правила, мы придерживались [Contributor Covenant](https://contributor-covenant.org). Это означает, что его бы тоже стоило почитать и вообще придерживаться данного завета. | ||
|
||
Учитывайте так же, что некоторые правила в целом-то можно нарушить, мы же не звери. Но главное: **не говноедить** и **желать сообществу добра**. Добро это всегда хорошо. |
Oops, something went wrong.