Skip to content

Commit 0f100e4

Browse files
feat: added more utility methods, improved translations functionality
1 parent 5008879 commit 0f100e4

File tree

199 files changed

+55269
-13271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+55269
-13271
lines changed

.DS_Store

0 Bytes
Binary file not shown.

README.md

Lines changed: 139 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,74 +38,163 @@ The Apple store will reject your app if it includes simulator binaries. Therefor
3838
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
3939

4040
# Compatibility
41-
We support latest Xcode 13+ and swift 5 (5.5) Version. This SDK requires base language as english. Other base language will not supported by this SDK
41+
This SDK requires base language as english. Other base language will not supported by this SDK
4242

43-
# Configuration
43+
- **iOS 13.0+** (Primary SDK functionality)
44+
- **Swift 5.0 or later**
45+
- Compatible with **Xcode 13.0+**
4446

45-
import DevnagriSdk
47+
## Import Requirements
4648

47-
Initialize the SDK by calling the following code in your didFinishLaunchingWithOptions Method and you can get API_KEY from devnagri
49+
To use DevNagri SDK in your Swift files, you must import the framework:
4850

49-
*updateStringTime* is an optional parameter
50-
For auto update strings translations you can set time in minutes.
51+
```swift
52+
import DevnagriSdk
53+
```
5154

52-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
53-
DevnagriSDK.shared.initSdk(apiKey: String, updateStringTime:Int?) { isInitialized, message in
54-
//Reload or update UI here...
55-
}
56-
}
57-
58-
# Default Localisation Override
59-
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.
55+
**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.
56+
57+
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.
58+
59+
---
60+
61+
## Public Methods & APIs
62+
Initialize the SDK by calling the following code in your `didFinishLaunchingWithOptions` Method and you can get `API_KEY` from devnagri.
63+
64+
```swift
65+
import DevnagriSdk
66+
67+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
6068

61-
# Change Language
62-
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.
63-
//You can start loader here...
64-
DevnagriSDK.shared.updateAppLocale(code: "hi") { isUpdated, message in
65-
//You can stop loader here...
66-
//Reload or update UI here...
67-
}
68-
69+
DevnagriSDK.shared.initSdk(
70+
apiKey: "YOUR_API_KEY",
71+
updateStringsTime: 30, // Minutes (minimum 10)
72+
completionHandler: { isInitialized, message in
73+
if isInitialized {
74+
print("SDK initialized successfully")
75+
} else {
76+
print("Initialization failed: \(message ?? "")")
77+
}
78+
}
79+
80+
)}
81+
```
82+
- `apiKey`: Your DevNagri API key (required)
83+
- `updateStringsTime`: Automatic translation update interval in minutes (optional, minimum 10)
84+
- `completionHandler`: Callback with initialization status and message
85+
86+
87+
# Language Management
88+
### **Change Language**
89+
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.
90+
91+
```swift
92+
import DevnagriSdk
93+
94+
DevnagriSDK.shared.updateAppLocale(code: "es") { isUpdated, message in
95+
//You can stop loader here...
96+
//Reload or update UI here...
97+
98+
}
99+
```
69100
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.
70-
71-
# Get Current language code
101+
102+
### **Get Current language code** ###
72103
In case you want to know which language code currently used by application.
73104

74-
let currentLanguageCode = DevnagriSDK.shared.getCurrentApplicationLanguageCode()
105+
```swift
106+
import DevnagriSdk
75107

76-
77-
# Get Supported Languages
108+
let currentLang = DevnagriSDK.shared.getCurrentApplicationLanguageCode()
109+
print("Current language: \(currentLang)") // e.g., "en", "es", "fr"
110+
```
111+
112+
### **Get Supported Languages** ###
78113
You can get supported languages for the SDK using this method. This will return hashmap of language name and language code
79114

80-
DevnagriSDK.shared.getAllSupportableLanguage{ arrOfLanguage in
81-
//do your stuff here ...
82-
}
83-
84-
# Translate String, List and Dictionary on runtime
115+
```swift
116+
import DevnagriSdk
117+
118+
DevnagriSDK.shared.getAllSupportableLanguages { languages in
119+
for language in languages {
120+
print("\(language.language) - \(language.languageCode)")
121+
// Example output: "Spanish - es", "French - fr"
122+
}
123+
}
124+
```
125+
126+
---
127+
128+
# Translation Methods
129+
### **Get Translation of a Specific String** ###
85130
You can use these methods anywhere in your project and these will provide translation for current active locale in callback method.
86131

87-
Get Translation of a Specific String
88132

89-
DevnagriSDK.shared.getTranslationOfString(sentence : "Hello"){ translatedString in
90-
//Do your stuff at here....
91-
}
133+
```swift
134+
import DevnagriSdk
92135

93-
Get Translations of an Array of Strings.
136+
DevnagriSDK.shared.getTranslationOfString(sentence: "Hello World") { translatedText in
137+
print("Translated: \(translatedText)")
138+
}
139+
```
94140

95-
let arrayOfStrings:[String] = ["SampleText1","SampleText2","SampleText3"];
96-
DevnagriSDK.shared.getTranslationsOfStrings(sentences : arrayOfStrings){translatedStrings
97-
//Do your stuff at here....
98-
}
141+
### **Get Translations of an Array of Strings.** ###
99142

100-
Get Translations Of Dictionary
143+
```swift
144+
import DevnagriSdk
101145

102-
let dicOfStrings:[String:String] = ["A":"SampleText1", "B":"SampleText2", "C":"SampleText3"];
103-
DevnagriSDK.shared.getTranslationOfDictionary(dictionary:[“Key1”:”Value1”, “Key2”:”Value 2”]){translatedDictionary in
104-
//Do your stuff at here....
105-
}
146+
let sentences = ["Hello", "Goodbye", "Welcome"]
147+
DevnagriSDK.shared.getTranslationOfStrings(sentences: sentences) { translatedArray in
148+
// Returns array of translated strings in same order
149+
print("Translated: \(translatedArray)")
150+
}
151+
```
106152

107-
Get Translations of Api response Json
153+
### **Get Translations Of Dictionary** ###
154+
155+
```swift
156+
import DevnagriSdk
157+
158+
let dict = ["title": "Hello", "subtitle": "Welcome"]
159+
DevnagriSDK.shared.getTranslationsOfDictionary(dictionary: dict) { translatedDict in
160+
// Returns dictionary with translated values, same keys
161+
print("Translated dictionary: \(translatedDict)")
162+
}
163+
```
164+
165+
### **Get Translations of Api response Json** ###
166+
```swift
167+
import DevnagriSdk
168+
169+
let jsonDict = ["user": ["name": "John", "id": "123"], "message": "Hello"]
170+
DevnagriSDK.shared.getTranslationOfDictionary(
171+
dict: jsonDict,
172+
ignoreKeys: ["id", "userId"], // Don't translate these keys
173+
callback: { translatedResponse in
174+
print("Translated JSON: \(translatedResponse)")
175+
}
176+
)
177+
```
178+
179+
180+
### **Refreshes subscription status and configuration from server.** ###
181+
182+
```swift
183+
import DevnagriSdk
184+
185+
DevnagriSDK.shared.refreshSubscriptionDetail()
186+
```
187+
188+
### **Performance tuning methods** ###
189+
190+
```swift
191+
import DevnagriSdk
192+
193+
DevnagriSDK.shared.setMaxRecursionCount(count: 50)
194+
DevnagriSDK.shared.setRecursionDurationInSeconds(seconds: 30)
195+
```
196+
197+
**How It Works:**
198+
- **setMaxRecursionCount**: Controls maximum retry attempts for API calls
199+
- **setRecursionDurationInSeconds**: Sets delay between retry attempts
108200

109-
DevnagriSDK.shared.getTranslationOfDictionary(dict: , igonreKeys: [""]) { translatedNSDictionary in
110-
//Do your stuff at here
111-
}

Sample-project/.DS_Store

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)