【问题标题】:L20n - how to translate custom attribute in htm tag?L20n - 如何翻译 html 标签中的自定义属性?
【发布时间】:2016-07-14 19:52:09
【问题描述】:

我有以下html标签:

<input type="text" data-l10n-id="message" data-validation-required-message="My message">

在翻译文件中我有:

<message placeholder:"Your message">

占位符属性有效,但我不知道如何翻译 data-validation-required-message 属性的内容

【问题讨论】:

    标签: html localization translation l20n


    【解决方案1】:

    它似乎只适用于标准属性。

    我能提出的唯一解决方案是通过 JavaScript 手动设置属性翻译。示例:

    l20n 文件

    <validationRequiredMessage "The Message">
    

    JavaScript

    document.l10n.formatValue( "validationRequiredMessage" ).then( ( t ) =>
        document.querySelector( "input" ).dataset.validationRequiredMessage = t
    )
    

    【讨论】:

    • 是的,这是我尝试的第一件事。但它不起作用。我怀疑值中的“-”可能会在这里造成问题......
    • 那么可能使用驼峰式表示法:dataValidationRequiredMessage:"My message"
    • 我无法控制属性名称是什么,它来自第 3 方框架。
    • 我的意思是在 l20n 文件中使用 camelCase 表示法,但它似乎也不起作用。对不起。
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多