Giter Club home page Giter Club logo

i18ner's Introduction

I18ner

Basic I18n library with no code generation or automatic translations' population.

Install

The main way of installing this library is using jitpack.io

repositories {
    // ...
    mavenCentral()
    maven("https://jitpack.io")
}

dependencies {
    // Replace TAG with the desired version
    implementation("net.lsafer.i18ner:i18ner:TAG")
    implementation("net.lsafer.i18ner:i18ner-yaml:TAG") // optional
}

Localization File Example

# Girl messages
my_message_name#en-US[F,0]=There is no girls here. No one to ask about {0}!
my_message_name#en-US[F,1]=Hey girl. Do you like {0}?
my_message_name#en-US[F,2..10]=Hey girls. Do you like {0}?
my_message_name#en-US[F,11..infinity]=Hey y'all girls. Do you like {0}?
# Boy messages
my_message_name#en-US[M,0]=There is no boys here. No one to ask about {0}!
my_message_name#en-US[M,1]=Hey man. Do you like {0}?
my_message_name#en-US[M,2..10]=Hey guys. Do you like {0}?
my_message_name#en-US[M,11..infinity]=Hey y'all men. Do you like {0}?
# An example of defining message attributes; `-` serves as an assignment operator
my_message_name_2[my_attr-my_attr_val]=Hello World
# An example of using named parameters
my_message_name_3=Oops, {first_person} just called {second_person} by mistake!

Or if you like yaml:

# Girl messages
my_message_name#en-US(F, 0): "There is no girls here. No one to ask about {0}!"
my_message_name#en-US(F, 1): "Hey girl. Do you like {0}?"
my_message_name#en-US(F, 2..10): "Hey girls. Do you like {0}?"
my_message_name#en-US(F, 11..infinity): "Hey y'all girls. Do you like {0}?"
# Boy messages
my_message_name#en-US(M, 0): "There is no boys here. No one to ask about {0}!"
my_message_name#en-US(M, 1): "Hey man. Do you like {0}?"
my_message_name#en-US(M, 2..10): "Hey guys. Do you like {0}?"
my_message_name#en-US(M, 11..infinity]: "Hey y'all men. Do you like {0}?"
# An example of defining message attributes; ` ` serves as an assignment operator
my_message_name_2(my_attr my_attr_val): "Hello World"
# An example of using named parameters
my_message_name_3: "Oops, {first_person} just called {second_person} by mistake!"

Runtime Configuration Example

val i18ner = I18ner() // or use the companion object I18ner 
i18ner.defaultLanguages += "ar-SA" // optional
i18ner.defaultLanguages += "en-US" // optional
i18ner.languageResolution = BasicTranslationLanguageResolution // optional
i18ner += i18nerSource {
    defaultLanguage = "ar-SA" // optional
    source = MyLocalizationFileSource
}

Runtime Usage Example

val i18ner = I18ner() // or use the companion object I18ner 

// using named parameters
i18ner.t("welcome", "name" to "Osama", "age" to 25) {
    // all optional
    languages += "ar-SA"
    languages += "en-US"
    count = 1
    gender = Gender.MALE
    attributes["my_attr"] = "my_attr_val"
}
// using positional parameters
i18ner.t("welcome", "Osama", "age") {
    // all optional
    languages += "ar-SA"
    languages += "en-US"
    count = 1
    gender = Gender.MALE
    attributes["my_attr"] = "my_attr_val"
}

i18ner's People

Contributors

lsafer-meemer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.