Learn how to install the Devnagri SDK for iOS.
Devnagri Over the Air for iOS lets you update translations in your iOS app without having to release it every single time.
By including our SDK, your app will check for updated translations in Devnagri regularly and download them in the background.
You can install the SDK manually.
Do note: The language selection screen needs to be designed by the client. We only empower localisation of the app.
Download the latest framework from https://github.com/DevnagriAI/ios-sdk Add DevnagriSdk.xcframework in Xcode as linked binary to your target.
Select project target and click general select in framework,libraries,and Embedded Content and select DevnagriSdk.xcframwork if not selected than choose Embed -> Embed & Sign.
- iOS 15.0+ (Minimum Supported Version)
- Swift 5.0 or later
- Compatible with Xcode 16.0+
- SDK Build with Xcode 16.4+
- The SDK requires English (en) as the base language. Other base languages are not supported.
- Your project must include an
en.lproj/Localizable.strings
file as the default resource. - If the base language file is missing, translations will not initialize properly.
NSLocalizedString
provides translations only for strings defined inside theen.lproj/Localizable.strings
file.- Adding
import DevnagriSdk
at the top of the file is required when using theNSLocalizedString
replacement functionality, as the SDK extends the localization system to work with its dynamic translation features.
To use DevnagriSdk SDK in your Swift files, you must import the framework:
import DevnagriSdk
Note: This import is required when using NSLocalizedString
method replacement functionality, as the SDK extends the localization system to work with SDK's dynamic translation features.
The SDK override the functionality of NSLocalisedString
by default. You just need to import the DevnagriSdk to the file where you want NSLocalisedString to be override by the SDK.
Initialize the SDK by calling the following code in your didFinishLaunchingWithOptions
Method and you can get API_KEY
from devnagri.
import DevnagriSdk
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DevnagriSDK.shared.initSdk(
apiKey: "YOUR_API_KEY",
updateStringsTime: 30, // Minutes (minimum 10)
completionHandler: { isInitialized, message in
if isInitialized {
print("SDK initialized successfully")
} else {
print("Initialization failed: \(message ?? "")")
}
}
)}
apiKey
: Your DevnagriSdk API key (required)updateStringsTime
: Automatic translation update interval in minutes (optional, minimum 10)completionHandler
: Callback with initialization status and message
In case you don't want to use the system language, you can set a different language in the updateAppLocale
method. The language code (locale) needs to be present in a release from Devnagri.
import DevnagriSdk
DevnagriSDK.shared.updateAppLocale(code: "es") { isUpdated, message in
//You can stop loader here...
//Reload or update UI here...
}
Please note that you will see the english text back if your device language is english and you have not set any specific language for the SDK. To get the translation in Hindi, Please update app locale to Hindi as per above method.
In case you want to know which language code currently used by application.
import DevnagriSdk
let currentLang = DevnagriSDK.shared.getCurrentApplicationLanguageCode()
print("Current language: \(currentLang)") // e.g., "en", "es", "fr"
You can get supported languages for the SDK using this method. This will return hashmap of language name and language code
import DevnagriSdk
DevnagriSDK.shared.getAllSupportableLanguages { languages in
for language in languages {
print("\(language.language) - \(language.languageCode)")
// Example output: "Spanish - es", "French - fr"
}
}
You can use these methods anywhere in your project and these will provide translation for current active locale in callback method.
import DevnagriSdk
DevnagriSDK.shared.getTranslationOfString(sentence: "Hello World") { translatedText in
print("Translated: \(translatedText)")
}
import DevnagriSdk
let sentences = ["Hello", "Goodbye", "Welcome"]
DevnagriSDK.shared.getTranslationOfStrings(sentences: sentences) { translatedArray in
// Returns array of translated strings in same order
print("Translated: \(translatedArray)")
}
import DevnagriSdk
let dict = ["title": "Hello", "subtitle": "Welcome"]
DevnagriSDK.shared.getTranslationsOfDictionary(dictionary: dict) { translatedDict in
// Returns dictionary with translated values, same keys
print("Translated dictionary: \(translatedDict)")
}
import DevnagriSdk
let jsonDict = ["user": ["name": "John", "id": "123"], "message": "Hello"]
DevnagriSDK.shared.getTranslationOfDictionary(
dict: jsonDict,
ignoreKeys: ["id", "userId"], // Don't translate these keys
callback: { translatedResponse in
print("Translated JSON: \(translatedResponse)")
}
)
import DevnagriSdk
DevnagriSDK.shared.refreshSubscriptionDetail()
import DevnagriSdk
DevnagriSDK.shared.setMaxRecursionCount(count: 10) //Number of attempt to get the translations if not received.
DevnagriSDK.shared.setRecursionDurationInSeconds(seconds: 30)
How It Works:
- setMaxRecursionCount: Controls maximum retry attempts for API calls
- setRecursionDurationInSeconds: Sets delay between retry attempts