从角度翻译文件存储访问存储的区域设置
accessing stored locale from angular-translate FileStorage
我在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
下面是模块和区域设置服务的 JSFiddle。 不可运行的代码。 只是我正在使用的代码的一个例子
我正在尝试访问currentLocale
但在用户(再次)做出选择之前它是未定义的。 我知道它存储在某个地方,因为浏览器退出后保留了原始选择。
在兔子整个 API 文档和角度翻译 * 源文件中大约 2 小时后,我发现我可以将$translateLocalStorage
传递给我的控制器,然后调用$translateLocalStorage.get()
它将返回缓存的 localId。
该方法从'$window.localStorage.getItem中提取localId。 该代码是
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();
}
});
相关文章:
- 存储$http如何从$http函数(Angularjs)外部获取可访问变量中的响应
- 访问存储对象
- 如何在本地存储(或其他数据库)上安全地保存敏感访问代码
- JavaScript-将多个对象存储在数组中,并通过访问它们的属性
- 在Phonegap/iOS中按下主页按钮时访问本地存储
- 存储在变量中的关联数组中的访问键
- 如何在Javascript中为不同的页面访问存储变量
- Pinterest 扩展如何存储(临时)网页中的图像,然后在 iframe 中访问它们
- 关闭并重新访问应用程序后,本地存储中的数据不会保留
- 通过存储在变量中的名称访问对象
- 将对象存储为JSON并在Javascript中访问它
- JavaScript:从html5中的本地存储访问Object[Object]
- 如何以及在何处安全地存储访问令牌
- 如何在BB10网络上存储访问密钥
- 具有存储访问权限的模型的类方法
- 数据存储/访问/写入/编辑和ajax调用
- 停止浏览器存储访问历史记录
- 我如何从数组存储访问JS函数
- 使用JavaScript变量存储访问SharePoint列表
- 从角度翻译文件存储访问存储的区域设置