title: How to dynamically decide the URL of translation tables dynamically with angular-translate custom loader?
body: <h3>How to dynamically decide the URL of translation tables dynamically with <code>$translateProvider</code></h3>
  
  <p>Currently, we follow - 
  [<a href="https://angular-translate.github.io/docs/#/guide/12_asynchronous-loading](asynchronous" rel="nofollow">https://angular-translate.github.io/docs/#/guide/12_asynchronous-loading](asynchronous</a> loading) in one of our application.We have followed this method for almost 2 years.But,right now we face a different task.We have to decide the URL of our translation file based on a logic.The logic is as follows,
  if file exists in given <code>location</code> then resolve translation through it or else fallback to <code>default location</code>. </p>
  
  <h3>My current environment</h3>
  
  <ul>
  <li>version of angular-translate - 2.4.2 with angular-translate-partial-loader - 2.4.2</li>
  <li>version of angular - 1.5</li>
  </ul>
  
  <h3>Structure of App</h3>
  
  <pre><code>|-- mod 1
  |   |-- de_de.json
  |   |-- en_us.json
  |   |-- es_es.json
  |   `-- zh_tw.json
  |-- mod 2
  |   |-- de_de.json
  ...Followed by corresponding translation files.
  </code></pre>
  
  <h3>Code structure:</h3>
  
  <p>application.js</p>
  
  <pre><code>myapp.config(['$translateProvider', '$translatePartialLoaderProvider',function ( $translateProvider, $translatePartialLoaderProvider ) {
      $translateProvider.useLoader( '$translatePartialLoader', {
          urlTemplate: 'i18n/{part}/{lang}.json'
      } );
      $translateProvider.preferredLanguage( "en_us" );
      $translateProvider.fallbackLanguage( "en_us" );
  }]);
  ........
  myapp.run( function ( $rootScope, $translate, editableOptions ) {
      $rootScope.$on( '$translatePartialLoaderStructureChanged', function () {
          $translate.refresh();
      } );
      editableOptions.theme = 'bs3';
  } );
  </code></pre>
  
  <p>controller1.js</p>
  
  <pre><code>myapp.controller1("Controller1",function($scope, ...,.., $translate, $translatePartialLoader,$rootScope) {
      /*@ngInject*/
      $translatePartialLoader.addPart('login');
      $translatePartialLoader.addPart('home');
  .......
   $scope.setLanguage = function(lang) {
       $translate.use(lang);
      }
  </code></pre>
  
  <p>So far so good.Now we want to change the logic of <code>application.js</code> to generate the translation table resolving URL.We have to check if we have translation tables for a <code>particular_part/in_particular_language</code> .</p>
  
  <h3>Expected Structure and behavior</h3>
  
  <pre><code>|-- mod 1
  |  |-- Custom
  |  |  |-- de_de.json
  |  |  |........followed by all custom translations for mod1 i.e, $translatePartialLoader.addPart('mod1') 
  |  |-- en_us.json
  |  |-- es_es.json
  |   `-- zh_tw.json
  |-- mod 2
  |   |-- de_de.json
  </code></pre>
  
  <p>In the new structure we will have Custom directory under each module,if there exists a translation file for a part/module in Custom then resolve using <code>part/Custom/lang_key.json else fall back to part/lang_key.json(as before)</code></p>
  
  <p>How can we achieve this through <code>ng-translate</code> ? .</p>
  
  <p>The approach I have gone ahead is by writing a <a href="https://angular-translate.github.io/docs/#/guide/13_custom-loaders" rel="nofollow">custom loader</a> .But the <code>options</code> of the <code>$translatePartialLoader</code> restricts the argument only to  lang_key which is passed by <code>$translate.use(lang_key)</code> .How can we get the <code>mod1</code> passed to <code>$translatePartialLoader.addPart('mod1')</code> into out <code>customLoader</code>.We cannot pass it to <code>$translate.use('lang_key/mod1')</code> as we call <code>$translate.use('land_key')</code> only once when the user logs in.</p>
  
  <p>If we can get the added module from <code>$translatePartialLoader('mod1')</code> call,passed into our <code>customLoader</code> then based on logic we can resolve translations accordingly.Currently, I am stuck on how to get the added part into <code>customLoader</code> as it is loaded by controllers(controller 1..).Is there a way or a custom service which should be written to get the added part/module.. into our <code>customLoader</code> if yes,can you guide me or help me with relevant code OR will we have to change the entire structure of the app - if changing the structure will help,then what the structure should be ?</p>
  
  <p>Thanks.</p>