有没有办法使用 ngx-translate 翻译 css 选择器(::after, ::before) 内容?

Dhi*_*esh 6 internationalization translate angular-translate ngx-translate angular

有没有办法使用 ngx-translate 翻译 css 选择器(::after, ::before) 内容?

.custom-file-label::after {
    content: "Browse"
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*eKh 7

在html中添加

 <div class="custom-file-label" [attr.your-custom] = "{{ 'Browse' | translate}}"></div>
Run Code Online (Sandbox Code Playgroud)

并在CSS中

.custom-file-label::after { 
        content: attr(your-custom);
 }
Run Code Online (Sandbox Code Playgroud)

  • 我们必须删除“[attr.your-custom]”周围的方括号,因为以下值是模板表达式,而不是 ts 类中的标识符。然后它工作得很好,但它给我们留下了一个警告,抱怨 your-custom 不是允许的属性。使用前缀“data-”也无济于事。 (2认同)