https://github.com/sauntor/stranslator
A most lightweight library for translating you application to the local languages.
https://github.com/sauntor/stranslator
internalization localization scala-i18n scala-l10n
Last synced: about 2 months ago
JSON representation
A most lightweight library for translating you application to the local languages.
- Host: GitHub
- URL: https://github.com/sauntor/stranslator
- Owner: sauntor
- License: apache-2.0
- Created: 2017-04-10T16:00:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-12T13:32:14.000Z (almost 9 years ago)
- Last Synced: 2023-12-15T05:36:00.607Z (about 2 years ago)
- Topics: internalization, localization, scala-i18n, scala-l10n
- Language: Scala
- Size: 29.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stranslator
A most lightweight library for translating you application to the local languages.
### The XML format for translation file
```xml
This is the original message!
这是原始文本!
這是原始文本!
```
### Usage
1. Add `Stranslator` to your project
```sbtshell
libraryDependencies += "com.lingcreative" %% "stranslator" % "1.1.0"
```
2. Code sample
```scala
import translator._
val translator = Translator()
val locale = new Locale("zh", "CN")
implicit val context = SimpleTranslatorContext(translator, Seq(locale))
val welcome = ${"Hello, Sauntor! Welcome to China!"}
```
If you create a translation file which is located in `l10n/translator.xml`(within the class path) with the flowing content:
```xml
Hello, Sauntor! Welcome to China!
适然,你好!欢迎来到中国!
```
The `welcome` would be:
`适然,你好!欢迎来到中国!`
###### Notice
1. the line feed(`\n`) after the beginning and before the ending tag of `from`, `locale`s (in `to` tag, i.e. `locale` stands for `` and ``), will be ignored.
2. you can break one line into multiple lines by putting an `\ ` to the end of the line(and the leading space is ignored and the space after `\ ` will be preserved).
For example:
```xml
Hello, \
Jack! I'm waiting \
for you!
捷克,你来了。\
我已经等你好久了!
```
The code above is equal to:
```xml
Hello, Jack! I'm waiting for you!
捷克,你来了。我已经等你好久了!
```
3. The default location to load translations from is `l10n/translator.xml`, i.e.
```scala
val translator = Translator()
```
Is equal to:
```scala
val translator = Translator("cp://l10n/translator.xml")
// Or to this:
//val translator = Translator("l10n/translator.xml")
```
4. You can `include` another xml for translations by ``tag :
```xml
http://example.com:9000/some/app/l10n/translations.xml
```
> The `` tag **does not** support **relative path**, i.e. you can't include a resource like `../some/other/module.xml`.
### About the `stranslator.Translator`
It's the core API for translating. You can initialize it with an URL. An class path resource will start with "cp://" (no prefix is identical to it too),
or an external resource on a **Web Server** with the corresponding uri pattern(i.e. http://example.com/l10n/demo-app.xml).
### Enjoy it! :tea: