问题
I want to add a translation for an HTML file which contains i.name. I do have an object called energydensity which contains the data I need for translation. This actually is a drop-down list and I want to convert that to Chinese.
I have tried this but this is displaying energy.energydensity in the drop-down list.
<option value="All">{{allLoads}}</option>
<option *ngFor="let i of ddlLoadType ;">{{'Energy.EnergyDensity.i.Name'}}</option>
</select>
<option value="All">{{allLoads}}</option>
<option *ngFor="let i of ddlLoadType ;">{{i.Name}}</option>
</select>
EN-US json data :
"EnergyDensity": {
"Heating": "Heating",
"Cooling": "Cooling",
"hvac": "HVAC",
"htg": "Heating",
"light": "Lighting",
"plgld": "Plug Load"
}
I want the whole drop-down list to be converted to Chinese.
回答1:
You might add something like:
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'},'google_translate_element');
}
</script>
This adds a Google Translate Button which translates your page to whatever language the user selects. There is a full example on w3schools.
来源:https://stackoverflow.com/questions/57159147/how-can-i-translate-an-html-file