简体   繁体   English

Angular - i18n 使用

[英]Angular - i18n uses

I want use the same label rendering different string depending on which user I use.我想使用相同的 label 根据我使用的用户呈现不同的字符串。

eg:例如:

For user 1:对于用户 1:

<h1>Hello I am the user 1</h1>

For user 2:对于用户 2:

<h1>What's up user 2?</h1>

I don't want use conditionals or so(maybe a.json? I don't know).我不想使用条件左右(也许是a.json?我不知道)。 It is a big project so I need something consistent.这是一个大项目,所以我需要一些一致的东西。

Any idea?任何想法?

You can delegate that to the component controller like this您可以像这样将其委托给组件 controller

<h1>{{userSpecificGreeting}}</h1>

and in component code并在组件代码中

get String userSpecificGreeting(){
    return this.getUserSpecificGreetingSomehow(this.currentUser); //do it here or delegate to a shared service
}

And if I understand your unclear comment maybe it would be good to encapsulate that as a separate component, pipe or directive so such greetings will be available for other componetns to use如果我理解您不清楚的评论,也许最好将其封装为单独的组件 pipe 或指令,以便其他组件可以使用此类问候语

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM