所以我沒有任何答案,我會回覆我迄今發現的。 ..雖然我提交了suggestion in Breeze user voice here
Breeze支持資源翻譯的答案目前尚不支持要做翻譯,我必須首先翻譯Breeze Validators
當我在EMFactory中開始微風時,我發現的方式是這樣的:
function emFactory($cookies, breeze, fileService) {
var lang = $cookies.lang || "en";
// load the validator templates translation mapping (external files: validators.{lang}.json)
var translations = loadValidatorsTranslation();
breeze.Validator.messageTemplates = translations[lang];
// Identify the endpoint for the remote data service
var serviceRoot = window.location.protocol + '//' + window.location.host + '/';
var serviceName = serviceRoot + 'breeze/BreezeApi';
var factory = {
newManager: function() { return new breeze.EntityManager(serviceName); },
serviceName: serviceName,
language: lang
};
return factory;
}
function loadValidatorsTranslation() {
return {
en: {
// ...
required: "'%displayName%' is required",
string: "'%displayName%' must be a string",
stringLength: "'%displayName%' must be a string with between %minLength% and %maxLength% characters",
url: "The %displayName% '%value%' is not a valid url"
},
fr: {
// ...
required: "'%displayName%' est requis",
string: "'%displayName%' doit être une chaîne de caractère",
stringLength: "'%displayName%' doit être une chaîne de caractère entre %minLength% et %maxLength% caractères",
url: "%displayName% '%value%' n'est pas un URL valide"
}
};
}
然後我創建了一個TranslationService
來處理d isplayNames我的微風背景下的實體:
appDemo.factory('translationService', ['$q', '$timeout', translationService]);
function translationService($q, $timeout) {
// declare the displayNames translations of entities
var displayMapping = {
fr: {
City: {
Name: "Nom de Ville"
},
Speaker: {
Bio: "Bio",
Image: "Image",
Name: "Nom du Conférencier"
}
},
en: {
City: {
Name: "City Name"
},
Speaker: {
Bio: "Bio",
Image: "Image",
Name: "Speaker Name"
}
}
};
// reveal the public functions & return the service
return {
loadTranslationDisplayNames: loadTranslationDisplayNames
};
// -- public functions
// --------------------
function loadTranslationDisplayNames(manager, lang, entityTypes) {
for (var i = 0, ln = entityTypes.length; i < ln; i++) {
// get the specific context Entity
var custType = manager.metadataStore.getEntityType(entityTypes[i]);
var entityProperties = displayMapping[lang][entityTypes[i]];
// loop through all properties of this Entity and update their DisplayName
for (var name in entityProperties) {
custType.getProperty(name).displayName = entityProperties[name];
}
}
}
}
終於在我的DataService,我打電話給我的TranslationService本
function dataService($rootScope, $q, breeze, entityManagerFactory, translationService) {
var service = this;
// reveal the public functions we want, any other functions will remain private
service.getSpeakers = getSpeakers;
var manager = entityManagerFactory.newManager();
var lang = entityManagerFactory.language;
return service;
// -- public/private functions declaration
function getSpeakers() {
var query = new breeze.EntityQuery.from("Speakers");
// load the translation of Breeze DisplayNames entities
translationService.loadTranslationDisplayNames(manager, lang, ["City", "Speaker"]);
startProcessingData();
var promise =
manager.executeQuery(query)
.catch(queryFailed)
.finally(processingDataComplete);
return promise;
}
}
...所以這項工作,我只是用我的新的翻譯更新我的TranslationService不管什麼時候我要。如果其他人有更好的/更清潔的解決方案,我會很樂意看到它...