gpt4 book ai didi

angular - 如何使用 $localize 传递变量

转载 作者:行者123 更新时间:2023-12-05 02:54:46 26 4
gpt4 key购买 nike

我正在使用 i18n 来翻译我的 Angular 2 应用程序。我需要从 ts 向翻译单元发送一个变量。

我有以下跨单元:

<trans-unit id="summary_hotel_tax" datatype="html">
<source>In <x id='INTERPOLATION' equiv-text='{{ citiesList }}'/> are taxes</source>
<target>A <x id='INTERPOLATION' equiv-text='{{ citiesList }}'/> pagare tassa turistica</target>
</trans-unit>

我尝试在我的 hotel.ts(组件)中执行以下操作:

$ localize`:@@summary_hotel_tax:In $ {citiesList} are taxes`;

但它不起作用。

我得到错误:

ERROR in There is a placeholder name mismatch with the translation provided for the
message "summary_hotel_tax" ("In {$PH} are taxes").The translation contains a
placeholder with name INTERPOLATION, which does not exist in the message.

我知道在使用 $localize 时它可能不是一个插值,在这种情况下我应该如何构造我的跨单元以从 $localize 向它发送一个变量。

最佳答案

我找到了以下解决方案并且对我有用:

$localize`:@@identification_trans_unit: Text text ${variable}:INTERPOLATION: another text`;

ID 必须放在变量旁边,在这种情况下:

 ${variable}:INTERPOLATION:

关于angular - 如何使用 $localize 传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61635509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com