• Resolved marcelgo

    (@marcelgo)


    Is there any way I can set 2 different languages for my Notify Button Texts? Seems like WPML String Translation is not supported.

    In the plugin settings I have changed it to my main language but there’s also an English version of my website where I need English texts.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hi @marcelgo,

    You can roughly follow this guide to do what you want: https://documentation.onesignal.com/docs/wordpress#section-customizing-wordpress-plugin-behavior.

    In that section above, follow the second bullet point (Never initialize OneSignal automatically, manually initialize OneSignal on target pages using client-sided JavaScript) and ignore the first bullet point.

    The code you can use will be similar to:

    
    function getCustomizedNotifyButtonTextByVisitorLanguage() {
      if (navigator.language === 'en-US') {
          window._oneSignalInitOptions.notifyButton.text['tip.state.unsubscribed'] = 'Subscribe to notifications';
      } else if (navigator.language === 'ja-JP') {
          window._oneSignalInitOptions.notifyButton.text['tip.state.unsubscribed'] = '通知を購読する';      
      }
    }
    
    window.OneSignal = window.OneSignal || [];
    /* Why use .push? See: https://stackoverflow.com/a/38466780/555547 */
    window.OneSignal.push(function() {
      /* Set notify button language text, see https://documentation.onesignal.com/docs/web-push-prompts#section-customize-subscription-bell */
     window._oneSignalInitOptions.notifyButton.text = getCustomizedNotifyButtonTextByVisitorLanguage();
      /* Never call init() more than once. An error will occur. */
      window.OneSignal.init(window._oneSignalInitOptions);
    });
    
Viewing 1 replies (of 1 total)
  • The topic ‘OneSignal for bilingual sites?’ is closed to new replies.