我想知道在我的练习中是否有任何不好的气味对于国际化的Angular。js i18n角度更好的练习
我把上的I18n角控制器转换功能(因为我不知道如何把它放在HTML模板文件)
约在国际化的范围,我用这种方式I18n.t("city." + city_name)
,表明是CITY_NAME在“城市”范围内。我可以用这种方式写出I18n.t(city_name, scope: "city")
,以使它更易于理解。
我很感谢每一个评论和建议,以加强我目前的解决方案。
数据结构
departures_lst是国家的英文名称e.g的列表,:[美国,中国,日本]
每个国家都有许多城市的名字。例如[纽约,洛杉矶,波士顿]
角控制器
App.controller("departures_ctrl", function($scope, $location, $http) {
$http.get("/departures.json")
.success(function (response) {
$scope.departures_lst = response;
});
$scope.get_destinations = function(city_name) {
return $location.url("/depart_from/" + city_name);
};
$scope.i18nCountryName = function(country_name) {
return I18n.t("country." + country_name) + country_name
};
$scope.i18nCityName = function(city_name) {
return I18n.t("city." + city_name) + city_name
};
});
HTML teamplate?
<div class="panel panel-transparent" ng-repeat="departure in departures_lst">
<h5>{{i18nCountryName(departure.country)}}</h5>
<li class="col-sm-3 col-lg-3 col-xs-3" ng-repeat="city in departure.cities">
<a ng-click="get_destinations(city)">
<i class="fa fa-plane"></i>
{{i18nCityName(city)}}
</a>
</li>
</div>
这大概是最好[代码审查(http://codereview.stackexchange.com/) – DrewJordan