Tuesday, June 5, 2012

5 steps for i18n in Windows 8 Metro style apps (JS)

  1. Create three folders in your project root:
    |
    --strings
      |
      --en-US
      |
      | 
      --de-DE (or another language and country code)
  2. Then create in your in each of your two subfolders a Resource File (*.resjson):
    |
    --strings
      |
      --en-US
      | |
      | --resources.resjson
      |
      --de-DE (or another language and country code)
        |
        --resources.resjson
    
  3. Enter your strings in JSON format.
  4. i18n in your HTML:
    1. <element data-win-res="{textContent: '[resStringName]'}"></element>
    2. Call WinJS.Resources.processAll() in your JavaScript, after the DOM was loaded, e.g.:
      var app = WinJS.Application;
      // ...
      app.onloaded = function (args) {
        WinJS.Resources.processAll();
      }
      
      
  5. i18n in your JavaScript:
    var str = WinJS.Resources.getString("[resStringName]").value;
    

No comments:

Post a Comment