You can specify a user's language in the Web SDK using one of the following methods. If you use both, the language set with setLanguage wins.
-
During SDK initialization: include the
Languagetag within thetagsobject in yourinitcall. If you don't pass it, the SDK uses the browser's language (navigator.language).Pushwoosh.push(['init', { logLevel: 'info', // error | info | debug applicationCode: 'XXXXX-XXXXX', apiToken: 'YOUR_DEVICE_API_TOKEN', // ... other init parameters tags: { 'Language': 'your_language_code' // e.g., 'en', 'fr', 'es' } }]);Replace
'your_language_code'with the language code you want, for example'en'or'es'(ISO 639-1). -
Using the
setLanguagefunction: after the SDK has been initialized, callsetLanguageto change the language of the current device. It overrides the value in theLanguagetag, and the SDK keeps your value on later page loads instead of re-applying the browser language or theinittag.Pushwoosh.push(function(api) { api.setLanguage('your_language_code'); // e.g., 'en', 'fr', 'es' });Use the language you set to localize push messages and to target users by language in segments.
See Web Push SDK 3.0 for the full list of API methods.
Comments
0 comments
Please sign in to leave a comment.