Javascript 从角度转换文件存储访问存储的区域设置

Javascript 从角度转换文件存储访问存储的区域设置,javascript,angularjs,angular-translate,Javascript,Angularjs,Angular Translate,我正在使用LocalStorage,它工作得非常好。区域设置缓存或存储在本地磁盘上。关闭并重新启动浏览器后,所选区域设置将保持不变 我的问题是如何访问我的控制器中磁盘上的缓存或存储区域设置?为了更好地解释以下工作流程,不起作用: 1. Launch browser to localhost and can see the site with previously chosen locale 2. Attempt to access the current locale from either t

我正在使用LocalStorage,它工作得非常好。区域设置缓存或存储在本地磁盘上。关闭并重新启动浏览器后,所选区域设置将保持不变

我的问题是如何访问我的控制器中磁盘上的缓存或存储区域设置?为了更好地解释以下工作流程,不起作用:

1. Launch browser to localhost and can see the site with previously chosen locale
2. Attempt to access the current locale from either the
    2.1 $translate.proposedLanguage()
    2.2 tmhDynamicLocale
3. Both are undefined -- even though the correct language is shown
4. Select language choice once more
5. current locale from both the above is now correct 
下面是模块和区域设置服务的示例。不可运行
代码。这只是我正在使用的代码的一个示例


我正在尝试访问
currentLocale
,但在用户(再次)做出选择之前,它是未定义的。我知道它存储在某个地方,因为在浏览器退出后,原始选择将被保留。

在一个完整的API文档和angular translate-*源文件中大约2小时后,我发现我可以将
$translateLocalStorage
传递给我的控制器,然后调用
$translateLocalStorage.get()
将返回缓存的本地化ID

该方法从“$window.localStorage.getItem”中提取本地化ID。那个密码是

get: function (name) {
    if(!langKey) {
      langKey = $window.localStorage.getItem(name);
    }

    return langKey;
  }
因此,您需要做的就是:

angular.module('myModule')
  .controller('QueryController', function($scope, es, $translateLocalStorage) {
     $scope.show_results = function(results) {
        var currentLocale = $translateLocalStorgae.get();
 }
});

这只是一个代码的粘贴,不打算成为工作示例!把问题缩短!有很多代码