title: Multi-Language-require.js project - optimize with r.js
body: <p>In our project we are using require.js for the module definition. The web project also provides multi-language support. For that case we use the require.js bundle i18n. Everything works until the optimization with r.js is processed.</p>
  
  <p>In the main.js file we have defined the following lines of code</p>
  
  <pre><code>config: {
      i18n: {
          locale: localStorage.getItem('locale') || 'de-de'
      }
  }
  </code></pre>
  
  <p>So it is possible for the user to switch the language. Somewhere in the code we have that:</p>
  
  <pre><code>    'click .lang-selection' : function(ev){
          localStorage.setItem('locale',$(ev.currentTarget).attr('data-language'));
          location.reload();
      }
  </code></pre>
  
  <p>But when it comes down to the optimization part with r.js, a problem occurs. </p>
  
  <p><em>Error: Error: The config in mainConfigFile /home/ch/html5-app/src/web/main.js cannot be used because it cannot be evaluated correctly while running in the optimizer. Try only using a config that is also valid JSON, or do not use mainConfigFile and instead copy the config values needed into a build file or command line arguments given to the optimizer.
      at Function.createConfig (/home/ch/html5-app/bin/r.js:24283:23)</em></p>
  
  <p>Does anybody have a solution for that or even another approach? For example building an own optimized file for each language?</p>
  
  <p>in addition the js.build.js file</p>
  
  <pre><code>    ({
      baseUrl: "../",
      name: "src/web/main",
      paths: {
          // require.js
          requirejs : 'vendor/backbone/require.215',
          // app specific modules
          root: 'src/web/app/js',
          templates : 'src/web/app/templates',
          // shared modules
          shared: 'src/shared/app/js',
          confighandler : 'src/shared/app/js/config/confighandler',
          root_config : 'src/web/app/js/config/config',
          layout: 'src/shared/app/js/views/layout',
          general: 'src/shared/app/js/general',
          helper: 'src/shared/app/js/helper',
          session: 'src/shared/app/js/session',
          vent: 'src/shared/app/js/vent',
          view: 'src/shared/app/js/views',
          model: 'src/shared/app/js/models',
          module : 'src/shared/app/js/modules',
          collection: 'src/shared/app/js/collections',
          nls : 'empty:',
          facebookSDK: 'empty:'
      },
      mainConfigFile: '../src/web/main.js',
      preserveLicenseComments: false,
      stubModules : ['text'],
      inlineText: true,
      // optimize: 'none',
      include: ['requirejs']
  })
  </code></pre>