Lang class
The Lang Facade.
Provides Laravel-style localization access from anywhere in your app, without needing BuildContext.
Usage
// Get a translation
Lang.get('welcome', {'name': 'Magic'});
// Change locale at runtime
await Lang.setLocale(Locale('tr'));
// Detect device locale
final detected = Lang.detectLocale();
// Listen to locale changes
Lang.addListener(() => print('Locale changed!'));
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
Static Methods
-
addListener(
VoidCallback listener) → void - Add a listener for locale changes.
-
choice(
String key, int number, [Map< String, dynamic> ? replace]) → String -
Get a translated string in the form that suits
number. -
detectAndSetLocale(
) → Future< Locale> - Detect and set the best matching locale from device/browser.
-
detectLocale(
) → Locale - Detect the best matching locale from device/browser.
-
get(
String key, [Map< String, dynamic> ? replace]) → String - Get a translated string.
-
has(
String key) → bool - Check if a translation key exists.
-
removeListener(
VoidCallback listener) → void - Remove a locale change listener.
-
setLocale(
Locale locale, {bool reload = true}) → Future< void> - Set the current locale at runtime.
-
setSupportedLocales(
List< Locale> locales) → void - Set supported locales.
Constants
-
delegate
→ const LocalizationsDelegate<
Translator> - Get the LocalizationsDelegate for Flutter.