如何在本地化文本中嵌入链接

时间:2021-02-04 03:53:35

Problem:

问题:

I am internationalizing an ASP.Net MVC application, but sentences with linked text have given me pause. Take the following as an example:

我正在国际化ASP。Net MVC应用程序,但是带有链接文本的句子让我犹豫。以以下为例:

  • English: "Please login to continue."
  • 中文:“请继续登入。”
  • Português: "Entre por favor para continuar."
  • 葡萄牙语:“中间倾向于延续段。”

Note that since "login" is hyperlinked, I must have the translator denote which corresponding word or phrase should be hyperlinked when the text is localized, e.g. Entre.

请注意,由于“login”是超链接的,所以当文本本地化时,我必须让翻译人员指明相应的单词或短语应该被超链接,例如。

I can't be the first to have this problem, so what is the best strategy-solution you have seen or used?

我不是第一个遇到这个问题的人,所以你见过或者用过的最好的策略解决方案是什么?

Is there a standard for denoting such things for a translator (and a standard way of using the translated results) ... or have I gone down the wrong path in expecting my content and presentation information to be so tightly coupled (although I can't think of any way to remove the coupling in this case).

是否有一个标准用于指示翻译人员(以及使用翻译结果的标准方法)……或者,我是否走错了路,期望我的内容和表示信息能够如此紧密地耦合(尽管在这种情况下,我想不出任何方法来删除耦合)。

Current Implementation:

当前的实现:

I am currently using local resource files for Views and an extension method on HtmlHelper to get the localized sting:

我目前正在使用本地资源文件进行视图,并使用HtmlHelper的扩展方法获得本地化的sting:

<%= Html.Resource("LoginMessage")%>

Update: Please see Keith's answer.

更新:请查看Keith的回答。

I found it most helpful, but the system auto selected another one.

我发现它非常有用,但是系统自动选择了另一个。

5 个解决方案

#1


5  

What I'm currently using is he following setup:

我现在使用的是他下面的设置:

I have a global resource file containing my primary texts, named Strings.resx (Strings.NL-nl.resx etc). Next to this I have my global file containing all localizations of my actionlinks. That is: ActionLinks.resx and locals.

我有一个全局资源文件,其中包含我的主要文本字符串。resx(Strings.NL-nl。resx等等)。下面是我的全局文件,包含所有actionlinks的本地化。这就是:ActionLinks。resx和当地人。

Now what I do is, in my Strings.resx I have something like:

现在我做的是,在我的字符串里。我有一些类似的东西:

Strings.resx

Strings.resx

Please {0} to continue

请继续{ 0 }

Local language Strings.NL-nl.resx

当地语言Strings.NL-nl.resx

{0} om verder te gaan

这是我的名片

Now the trick is to do something like:

现在的诀窍是:

<%= Html.Encode(string.Format(Resources.Strings.ControllernameViewnameKey, 
Html.ActionLink(Resources.ActionLinks.login, "Account", "LogOn")))

If you need more than one variable in your link you can give an array of objects to

如果在链接中需要多个变量,可以为其提供一个对象数组

 string.Format()

The keynaming is my own convention to understand where the maintext is used (what page). Since my maintexts are very specific. Of course keys can be made yourself.

keyname是我自己的约定,用于理解在哪里使用主文本(什么页面)。因为我的主题很具体。当然,钥匙可以自己做。

For more information on how I do it you can have a look at my answer on my own question: here

要了解更多关于我如何做这件事的信息,你可以看看我对我自己的问题的回答:这里


Edit

编辑

Of course you can use local files instead of global files but I like my strongly typed resources too much for that :).

当然,您可以使用本地文件而不是全局文件,但我太喜欢我的强类型资源了:)。

#2


11  

I think this comes down to 4 choices:

我认为这可以归结为四个选择:

  1. Put a link in your localisation: "Please <a href="#">login</a> to continue"
  2. 在本地化中添加链接:“请登录继续”
  3. Multiple localisations - either:
    1. "Please {0} to continue" and "login", or
    2. “请{0}继续”和“登录”,或
    3. "Please", "login" and " to continue"
    4. “请”、“登入”及“继续”
  4. 多重定位——要么:“请{0}继续”和“登录”,要么“请”、“登录”和“继续”
  5. Markup inside your localisations, for instance:
    1. "Please {0}login{1} to continue"
    2. “请{ 0 } { 1 }继续登录”
    3. "Please {start-login}login{end-login} to continue"
    4. “请{ start-login } { end-login }继续登录”
    5. "Please <a href="{0}">login</a> to continue"
    6. "请登录继续"
  6. 例如:“请{0}登录{1}继续”“请启动登录”{0}“请继续”“请登录继续”
  7. Just don't support it - make the whole sentence a link
  8. 不要支持它——把整个句子变成一个链接

I think there is a major reason to avoid 1 - you mix up localisations and application navigation.

我认为避免1的一个主要原因是:您混淆了本地化和应用程序导航。

Option 2 ends up with multiple resources for each block of text, but as long as you have good ways of managing all your localisations it shouldn't be an issue. It can be a pain for 3rd-party translators though - you need some way to tell them the context or you get some very weird translations of the individual words.

选项2为每个文本块提供了多个资源,但是只要您有管理所有本地化的好方法,就不应该成为问题。但是,对于第三方译者来说,这可能是一件痛苦的事情——你需要某种方式告诉他们上下文,或者你得到一些非常奇怪的单个词的翻译。

Option 3 is my preferred solution. You still create issues for your translators though - most will not understand your tokens/HTML/markup in the text. Ours already do some HTML, so 3.3 has worked for us.

选项3是我首选的解决方案。您仍然为您的翻译人员创建问题-大多数人将不理解您的令牌/HTML/标记在文本中。我们已经做了一些HTML,所以3.3已经为我们工作了。

Option 4 might be worth considering - do you gain enough in having the link embedded in order to make it worth the extra work and maintenance? It's an important question specific to your application: if the whole sentence is the link (rather than just the active verb - which is link best practice) do you really lose enough to make option 2 or 3 worth the additional effort?

选项4可能值得考虑——您是否已经获得足够的嵌入链接,以使其值得进行额外的工作和维护?这是一个特定于应用程序的重要问题:如果整个句子是链接(而不仅仅是主动动词——这是链接最佳实践),那么您是否真的失去了足够的东西,使选项2或3值得付出额外的努力?

I think this might be why there aren't more standardised ways of doing this as for most projects (maybe 9 times out of 10) option 4 is sufficient, so this only ends up as a problem for some special cases. We have a complex application with around 11,000 pieces of localised text and go for 4 the vast majority of the time, and have only 4 or 5 places where we've had to go with 3.3

我认为这可能就是为什么对于大多数项目(可能10次中有9次),没有更多标准化的方法来实现这个目标的原因,所以这只会在某些特殊情况下成为问题。我们有一个复杂的应用程序,大约有11000条本地化的文本,绝大多数时候是4条,只有4或5条地方需要3.3

Our technical implementation is similar to yours:

我们的技术实现与你们相似:

<%= Html.Localise("Controller/Action/KeyOfTextOnPage") %>

For links we have a specific helper:

对于链接,我们有一个特定的助手:

<%= Html.LocaliseLink("Controller/Action/KeyOfTextOnPage", "~/link.aspx") %>
<%= Html.LocaliseAction("Controller/Action/KeyOfTextOnPage", "action", "controller") %>

#3


1  

I'd suggest separating the resource into two values, like this
- 1: Please {0} to continue.
- 2: login

我建议将资源分成两个值,如:1:请{0}继续。- 2:登录

or for Português
- 1: {0} por favor para continuar.
- 2: Entre

或者对于葡萄牙- 1:{0}por,表示对延续的偏好。- 2:之间

And then combine them to build the link and message. {0} is substitued for the link/actionlink/whatever you need.

然后结合它们来构建链接和消息。{0}代替了链接/actionlink/你需要的任何东西。

#4


1  

I'd simply look for custom placeholders that index to the link that you want placed around the text. Eg

我只需要寻找自定义占位符,该占位符索引到要放置在文本周围的链接。如

"Please #123#login#123# to continue"

If you find #n# in your string, you know that the string that it surrounds should be a link to the url specified by index n in your lookup file (db, or whatever).

如果在字符串中发现#n#,那么您就知道它所包围的字符串应该是指向查找文件(db或其他)中的索引n指定的url的链接。

#5


1  

I have to agree with other answers - separate in 2.

我必须同意其他的答案——在2中分开。

That said I would add that don't consider the 2 words separated / unrelated. Stick to a simple convention all around like: LoginMessage & LoginMessageLink, corresponding to the whole text of the sentence & the text of the link.

这就是说,我要补充的是,不要把这两个词分开。遵循一个简单的约定:LoginMessage & LoginMessageLink,对应于整个句子的文本和链接的文本。

That's neutral & if that's what needed for the language the translator can have the whole sentence be the link.

这是中立的&如果这是语言所需要的,译者可以让整个句子成为链接。

If you find yourself needing to link several times to the same page, then instead have some markers for it. Like:

如果您发现自己需要多次链接到同一个页面,那么您可以使用一些标记。如:

English: "Please ##login## to continue."
Português: "##Entre## por favor para continuar."

#1


5  

What I'm currently using is he following setup:

我现在使用的是他下面的设置:

I have a global resource file containing my primary texts, named Strings.resx (Strings.NL-nl.resx etc). Next to this I have my global file containing all localizations of my actionlinks. That is: ActionLinks.resx and locals.

我有一个全局资源文件,其中包含我的主要文本字符串。resx(Strings.NL-nl。resx等等)。下面是我的全局文件,包含所有actionlinks的本地化。这就是:ActionLinks。resx和当地人。

Now what I do is, in my Strings.resx I have something like:

现在我做的是,在我的字符串里。我有一些类似的东西:

Strings.resx

Strings.resx

Please {0} to continue

请继续{ 0 }

Local language Strings.NL-nl.resx

当地语言Strings.NL-nl.resx

{0} om verder te gaan

这是我的名片

Now the trick is to do something like:

现在的诀窍是:

<%= Html.Encode(string.Format(Resources.Strings.ControllernameViewnameKey, 
Html.ActionLink(Resources.ActionLinks.login, "Account", "LogOn")))

If you need more than one variable in your link you can give an array of objects to

如果在链接中需要多个变量,可以为其提供一个对象数组

 string.Format()

The keynaming is my own convention to understand where the maintext is used (what page). Since my maintexts are very specific. Of course keys can be made yourself.

keyname是我自己的约定,用于理解在哪里使用主文本(什么页面)。因为我的主题很具体。当然,钥匙可以自己做。

For more information on how I do it you can have a look at my answer on my own question: here

要了解更多关于我如何做这件事的信息,你可以看看我对我自己的问题的回答:这里


Edit

编辑

Of course you can use local files instead of global files but I like my strongly typed resources too much for that :).

当然,您可以使用本地文件而不是全局文件,但我太喜欢我的强类型资源了:)。

#2


11  

I think this comes down to 4 choices:

我认为这可以归结为四个选择:

  1. Put a link in your localisation: "Please <a href="#">login</a> to continue"
  2. 在本地化中添加链接:“请登录继续”
  3. Multiple localisations - either:
    1. "Please {0} to continue" and "login", or
    2. “请{0}继续”和“登录”,或
    3. "Please", "login" and " to continue"
    4. “请”、“登入”及“继续”
  4. 多重定位——要么:“请{0}继续”和“登录”,要么“请”、“登录”和“继续”
  5. Markup inside your localisations, for instance:
    1. "Please {0}login{1} to continue"
    2. “请{ 0 } { 1 }继续登录”
    3. "Please {start-login}login{end-login} to continue"
    4. “请{ start-login } { end-login }继续登录”
    5. "Please <a href="{0}">login</a> to continue"
    6. "请登录继续"
  6. 例如:“请{0}登录{1}继续”“请启动登录”{0}“请继续”“请登录继续”
  7. Just don't support it - make the whole sentence a link
  8. 不要支持它——把整个句子变成一个链接

I think there is a major reason to avoid 1 - you mix up localisations and application navigation.

我认为避免1的一个主要原因是:您混淆了本地化和应用程序导航。

Option 2 ends up with multiple resources for each block of text, but as long as you have good ways of managing all your localisations it shouldn't be an issue. It can be a pain for 3rd-party translators though - you need some way to tell them the context or you get some very weird translations of the individual words.

选项2为每个文本块提供了多个资源,但是只要您有管理所有本地化的好方法,就不应该成为问题。但是,对于第三方译者来说,这可能是一件痛苦的事情——你需要某种方式告诉他们上下文,或者你得到一些非常奇怪的单个词的翻译。

Option 3 is my preferred solution. You still create issues for your translators though - most will not understand your tokens/HTML/markup in the text. Ours already do some HTML, so 3.3 has worked for us.

选项3是我首选的解决方案。您仍然为您的翻译人员创建问题-大多数人将不理解您的令牌/HTML/标记在文本中。我们已经做了一些HTML,所以3.3已经为我们工作了。

Option 4 might be worth considering - do you gain enough in having the link embedded in order to make it worth the extra work and maintenance? It's an important question specific to your application: if the whole sentence is the link (rather than just the active verb - which is link best practice) do you really lose enough to make option 2 or 3 worth the additional effort?

选项4可能值得考虑——您是否已经获得足够的嵌入链接,以使其值得进行额外的工作和维护?这是一个特定于应用程序的重要问题:如果整个句子是链接(而不仅仅是主动动词——这是链接最佳实践),那么您是否真的失去了足够的东西,使选项2或3值得付出额外的努力?

I think this might be why there aren't more standardised ways of doing this as for most projects (maybe 9 times out of 10) option 4 is sufficient, so this only ends up as a problem for some special cases. We have a complex application with around 11,000 pieces of localised text and go for 4 the vast majority of the time, and have only 4 or 5 places where we've had to go with 3.3

我认为这可能就是为什么对于大多数项目(可能10次中有9次),没有更多标准化的方法来实现这个目标的原因,所以这只会在某些特殊情况下成为问题。我们有一个复杂的应用程序,大约有11000条本地化的文本,绝大多数时候是4条,只有4或5条地方需要3.3

Our technical implementation is similar to yours:

我们的技术实现与你们相似:

<%= Html.Localise("Controller/Action/KeyOfTextOnPage") %>

For links we have a specific helper:

对于链接,我们有一个特定的助手:

<%= Html.LocaliseLink("Controller/Action/KeyOfTextOnPage", "~/link.aspx") %>
<%= Html.LocaliseAction("Controller/Action/KeyOfTextOnPage", "action", "controller") %>

#3


1  

I'd suggest separating the resource into two values, like this
- 1: Please {0} to continue.
- 2: login

我建议将资源分成两个值,如:1:请{0}继续。- 2:登录

or for Português
- 1: {0} por favor para continuar.
- 2: Entre

或者对于葡萄牙- 1:{0}por,表示对延续的偏好。- 2:之间

And then combine them to build the link and message. {0} is substitued for the link/actionlink/whatever you need.

然后结合它们来构建链接和消息。{0}代替了链接/actionlink/你需要的任何东西。

#4


1  

I'd simply look for custom placeholders that index to the link that you want placed around the text. Eg

我只需要寻找自定义占位符,该占位符索引到要放置在文本周围的链接。如

"Please #123#login#123# to continue"

If you find #n# in your string, you know that the string that it surrounds should be a link to the url specified by index n in your lookup file (db, or whatever).

如果在字符串中发现#n#,那么您就知道它所包围的字符串应该是指向查找文件(db或其他)中的索引n指定的url的链接。

#5


1  

I have to agree with other answers - separate in 2.

我必须同意其他的答案——在2中分开。

That said I would add that don't consider the 2 words separated / unrelated. Stick to a simple convention all around like: LoginMessage & LoginMessageLink, corresponding to the whole text of the sentence & the text of the link.

这就是说,我要补充的是,不要把这两个词分开。遵循一个简单的约定:LoginMessage & LoginMessageLink,对应于整个句子的文本和链接的文本。

That's neutral & if that's what needed for the language the translator can have the whole sentence be the link.

这是中立的&如果这是语言所需要的,译者可以让整个句子成为链接。

If you find yourself needing to link several times to the same page, then instead have some markers for it. Like:

如果您发现自己需要多次链接到同一个页面,那么您可以使用一些标记。如:

English: "Please ##login## to continue."
Português: "##Entre## por favor para continuar."