setLanguage method
Set the user's app language so campaigns are delivered localized to it
(e.g. setLanguage('en') / setLanguage('ar')). Call it at startup with
the app's current locale, and again whenever the user changes it. The code
is attached to the device token; a campaign with content for that language
is sent in it, otherwise the campaign's default language is used.
Safe to call before or after push is enabled — if a token is already registered it re-registers immediately; otherwise the language is applied on the next registration.
Implementation
Future<void> setLanguage(String lang) async {
final code = lang.trim();
if (code.isEmpty || code == _lang) return;
_lang = code;
final token = _token;
final platform = _lastPlatform;
if (token != null && platform != null) {
await registerToken(token, platform: platform, provider: _lastProvider);
}
}