Angular i18n-错误:无法在可翻译区域内将元素标记为可翻译

时间:2019-06-04 07:19:46

标签: angular angular-i18n

在Angular 7应用程序中,我有一个带有这样的嵌套标签的html-

cities = []
aqi = []


# 5 pollutants used to calculate AQI
CO = []
NO2 = []
SO2 = []
pm25 = []


for city in canadian_cities:
    city_name = city
    url = f'https://api.waqi.info/feed/{city}/?token={api_key}'
    response = requests.get(url).json()
    if (response["status"] == "ok"):
        # sometime aqi might not be a number, exclude them

        print("yes")
        if (isinstance(response["data"]["aqi"], int)):
            # append aqi and city name to appropriate list
            aqi.append(response["data"]["aqi"])
            cities.append(city)

            # append pollutants individually
            try:
                CO.append(response["data"]["iaqi"]["co"]["v"])
            except:
                CO.append("na")
            try:
                NO2.append(response["data"]["iaqi"]["no2"]["v"])
            except:
                NO2.append("na")
            try:
                SO2.append(response["data"]["iaqi"]["o3"]["v"])
            except:
                SO2.append("na")
            pm25.append(response["data"]["iaqi"]["pm25"]["v"])

执行以下命令时

<p i18n="@@footerText">Some Text Here 
  <a i18n="@@footerLink" href="http://url.com" target="_blank">Link Text</a> 
  Another Text Here
</P>        

它引发错误-
错误:无法在可翻译部分内将元素标记为可翻译

  

如何将i18n与嵌套标签一起使用?

1 个答案:

答案 0 :(得分:1)

<p>
  <ng-container i18n="@@footerPrefix">Some Text Here</ng-container> 
  <a i18n="@@footerLink" href="http://url.com" target="_blank">Link Text</a> 
  <ng-container i18n="@@footerSuffix">Another Text Here</ng-container> 
</p>

或者只是将所有内容(包括链接)放入您的翻译中

<p i18n="@@footerText">Some Text Here 
  <a href="http://url.com" target="_blank">Link Text</a> 
  Another Text Here
</p>