从资源文件链接到资源

发布于 2025-01-04 14:48:05 字数 170 浏览 3 评论 0原文

我有一个全局资源文件:ContactDetails.resx。这里是网站上使用的地址和联系信息。

我还有一个联系页面,列出了所有联系方式,但根据语言而变化。因此,在英国网站上,英国联系方式将显示在顶部,而在法国网站上,法国详细信息将显示在顶部。

有没有办法嵌套资源,从不同资源的值中引用资源值?

I have a global resource file: ContactDetails.resx. In here are addresses and contact information used around the website.

I also have a contact page listing all the contact details, but changing depending on language. So on the UK website, the UK contact details appear at the top, whereas on the French website the French details will appear at the top.

Is there a way to nest resources, referencing a resource value from within the value of a different resource?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2025-01-11 14:48:05

如果某个资源值在您的法语资源文件中不存在,但在您的默认资源文件中存在,则系统将自动从默认资源文件中获取该值。

因此,如果您的本地化设置为 fr,并且您的呼叫类似于:

Resources.ContactDetails.Telephone

并且 ContactDetails.fr.resx 中不存在电话,那么它将从以下位置获取电话值: ContactDetails.resx


如果所有值都显示在页面上,但根据本地化以不同的顺序显示,我建议不要将这些值存储在资源文件中。资源文件变体是为了更改语言,而不是更改数据布局。

相反,我建议将它们存储在数据库中,并在页面上有 3 个文字控件,例如:

<asp:literal id="ltl1stTelephone" runat="server" />
<asp:literal id="ltl2ndTelephone" runat="server" />
<asp:literal id="ltl3rdTelephone" runat="server" />

然后根据本地化,指定应为每个控件分配哪些值。

if (System.Threading.Thread.CurrentThread.CurrentUICulture = "fr"){
   .........
}

If a resource value doesn't exist in your French resource file, but does in your Default resource file, the system will automatically get the value from the default resource file.

So if your localization is set to fr, and your call is something like:

Resources.ContactDetails.Telephone

And Telephone doesn't exist in ContactDetails.fr.resx then it will get the Telephone value from ContactDetails.resx


If all the values are to be displayed on the page, but in a different order depending on the localization I would recommend not storing these in a resource file. The resource file variations are for changes in language, not to change layout of data.

Instead I would recommend to store these in the database, and have 3 literal controls on the page like:

<asp:literal id="ltl1stTelephone" runat="server" />
<asp:literal id="ltl2ndTelephone" runat="server" />
<asp:literal id="ltl3rdTelephone" runat="server" />

Then depending on the localization, specify which values should be assigned to each control.

if (System.Threading.Thread.CurrentThread.CurrentUICulture = "fr"){
   .........
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文