Skip to content

Instantly share code, notes, and snippets.

@bkardell
Last active December 14, 2015 13:58
Show Gist options
  • Save bkardell/5097148 to your computer and use it in GitHub Desktop.
Save bkardell/5097148 to your computer and use it in GitHub Desktop.
some locale ideas
<script>
  var suchiConfig = suchiConfig || [];
  
  // EACH OF THE BELOW IS A SUCHI CONFIG... I JUST REMOVED THE NOISE

  // Move related configs into their relevant objects
  var exampleA = {
    "prompt": {
      "id": "notice",
      //... etc ...
    }
  }
  
  // pass useful data to the lag fn... sometimes it will be undefined, that sucks,
  // but it's a nice pattern... it could be an argument with named props too?
  var exampleB = {
    "prompt": {
      "id": "notice"
    },
    onlagging: function(messages, prompt_el) {
      //  If I have i18n/i10n in a server environment like php or jsp or something
      //  I can take care of it most efficiently and accurately here
    }
  }
  
  
  // Allow them to provide some messages manually... If you don't have a server environment
  // this could be useful... I have most of this implemented in my fork:
  // It looks at the navigator.language first, then falls back to navigator.userLanguage, 
  // then back to navigator.browserLangauge as IE is f*cked 
  // https://developer.mozilla.org/en-US/docs/DOM/window.navigator.language 
  // To resolve the message, it looks for your language.  If it doesn't find it and it has a "-" (as in en-uk)
  // it looks up a level (for "en") and if that is not found, it considers your defaults (we can add a base default too)
  var exampleB = {
    "prompt": {
      "id": "notice",
      "defaultLocales": ['en-uk']
      "messages": {
        "en-uk": "Yadda yadda yadda.",
        "en-us": "Yadda yadda yadda.",
        "en": "Your browser sucks!!",
        "es":  "Su navegador chupa"
      }
    }
  }
  
  
  // allow me to specify where messages can be retrieved by uri with a server side mechanism
  // which can consider my accept headers (most optimal and simply returns the actual text/fragment)
  var exampleB = {
    "prompt": {
      "id": "notice",
      "messages": "/path/to/"
    }
  }
  
  
  // auto load suchi prompts... not entirely sure how we do this well.  Seems the easiest thing is to 
  // ensure a file for every locale and template the path?
  var exampleB = {
    "prompt": {
      "id": "notice",
      "messages": true
    }
  }
  
  
  
  
  
</script>
@slightlyoff
Copy link

yeah, I don't think there's any bundle support now that I read it again. I think it dropped out as a result of some ambiguities about encoding and indexing.

Looks like we should use real RFC 5646 indexes into the messages list: http://tools.ietf.org/html/rfc5646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment