Skip to content

lingohub/lh-android-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

LingoHub Android SDK

Features

  • Over-The-Air localization update
  • Localization testing using preproduction builds

Requirements

  • minSdk 16

Installation

Add the jitpack maven repository to your top level .gradle file:

allprojects {
    repositories {
        ...
        maven {
            url 'https://jitpack.io'
        }
    }
}

Now, add the LingoHub dependeny to your application level .gradle file:

dependencies {
    ...
    implementation 'com.lingohub:lh-android-sdk:x.y.z'
}

(Please replace x.y.z with the latest version numbers: )

Usage

Configuration

Configure the LingoHub SDK in your Application class with:

  • Application Context
  • API Key
  • Project Id
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        
        LingoHub.configure(this, "<api key>", "<project id>")
        
        // Add following line only if you want to use pre-production packages.
        LingoHub.setPreproductionEnabled()
        
        // Fetch the latest translations from LingoHub
        LingoHub.fetchStrings()
}

LingoHub needs to be wrapped around the activity context in order to replace strings. We recommend implementing a BaseActivity class from which all your other Activity classes extend.

abstract class BaseActivity : AppCompatActivity() {

    private val lingohubDelegate: AppCompatDelegate by lazy {
        LingoHub.getAppCompatDelegate(this, super.getDelegate())
    }
    
    override fun getDelegate() = lingohubDelegate

}

That's it!

In case you are loading strings from parts of your application where LingoHub is not injected (e.g. custom views) you can load strings manually:

val lingoHubResources = LingoHubResources(this)
val myString = lingoHubResources.getString(R.string.my_string)

or if you need to load strings provided via custom attributes:

val lingoHubResources = LingoHubResources(context)
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0)
val stringId = typedArray.getResourceId(R.styleable.PieChart_myString, -1)
if(stringId != -1){
    textView.text = lingoHubResources.getString(stringId)
}

Language switching

If you would like to change the language of your app at runtime, you can use the LingoHub SDK for it.

LingoHub.setLocale(locale)

Preproduction mode

If you would like to test your localizations before submitting a new package, enable preproduction mode.

LingoHub.setPreproductionEnabled()

Troubleshooting

If you can't get the SDK to work, use the LingoHubLogger class to find out the cause of the problem.

LingoHub.setLogger(object : LingoHubLogger {

    override fun onInfo(message: String) {
        Log.d("LH SDK", message)
    }
    
    override fun onError(error: String, cause : Throwable?) {
        Log.e("LH SDK", error, cause)
    }
   
})

Support

For bug reports, please create a new Issue right here on Github. Otherwise have a look at our Contact options

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published