LanguageHelper class

Make it easier for you to control multiple languages in your app

Available Extensions

Constructors

LanguageHelper(String prefix)
Prefer using the built-in instance of LanguageHelper when possible instead of creating a custom one. Utilizing the built-in instance allows access to all extension methods (such as tr, trP, trT, trF) and builder widgets (like LanguageBuilder and Tr) without the need to pass the instance explicitly to each. This approach simplifies usage and ensures consistency across your application.

Properties

code LanguageCodes
Get current language as LanguageCodes
no setter
codeKey String
Language code preferences key
no setter
codes Set<LanguageCodes>
Get list of LanguageCodes of the data and dataOverrides
no setter
codesOverrides Set<LanguageCodes>
Get list of LanguageCodes of the dataOverrides
no setter
data LanguageData
Get the current data as LanguageData.
no setter
dataOverrides LanguageData
Get the current dataOverrides as LanguageData.
no setter
deviceCodeKey String
Language code of the device
no setter
ensureInitialized Future<void>
Wait until the initial method is completed.
no setter
hashCode int
The hash code for this object.
no setterinherited
isDebug bool
Print debug log
no setter
isInitialized bool
Return true if the initial method is completed.
no setter
locale Locale
Get current language as Locale
no setter
locales Set<Locale>
Get list of language as Locale
no setter
prefix String
Prefix of the key to save the data to SharedPreferences.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<LanguageCodes>
Stream on changed. Please remember to close this stream subscription when you are done to avoid memory leaks.
no setter

Methods

addData(LanguageDataProvider data, {bool overwrite = true, bool activate = true}) Future<void>
Add new data to the current data.
addDataOverrides(LanguageDataProvider dataOverrides, {bool overwrite = true, bool activate = true}) Future<void>
Add new data to the current dataOverrides.
analyze() String
Analyze the _data so you can know which ones are missing what text. The results will be print in the console log with the below format:
change(LanguageCodes toCode) Future<void>
Change the language to this code
dispose() → void
Dispose all the controllers
initial({required Iterable<LanguageDataProvider> data, Iterable<LanguageDataProvider> dataOverrides = const [LanguageDataProvider.empty()], Iterable<String> analysisKeys = const {}, LanguageCodes? initialCode, bool useInitialCodeWhenUnavailable = false, bool forceRebuild = false, bool isAutoSave = true, bool syncWithDevice = true, bool isOptionalCountryCode = true, void onChanged(LanguageCodes code)?, bool isDebug = false}) Future<void>
Initialize the plugin with the List of data that you have created, you can set the initialCode for this app or it will get the first language in data, the LanguageCodes.en will be added when the data is empty. You can also set the forceRebuild to true if you want to rebuild all the LanguageBuilder widgets, not only the root widget (it will decreases the performance of the app). The onChanged callback will be called when the language is changed. Set the isDebug to true to show debug log.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reload() Future<void>
Reload all the LanguageBuilder to apply the new data.
setUseInitialCodeWhenUnavailable(bool newValue) → void
Change the useInitialCodeWhenUnavailable value
toString() String
A string representation of this object.
inherited
translate(String text, {Map<String, dynamic> params = const {}, LanguageCodes? toCode}) String
Translate this text to the destination language

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance LanguageHelper
final