.resx 文件或 Redis 中的语言字符串?

发布于 2025-01-06 02:10:00 字数 220 浏览 2 评论 0原文

我正在尝试为一个新网站建模(到目前为止仅在纸上),并且我开始思考什么可能是最好的方法。该网站需要是多语言的(至少两种语言)。由于我最近开始测试 Redis,我想也许我可以在 Redis 中而不是在 .resx 文件中存储语言库。

我知道这是可行的,但是值得吗?它是否有可能提高性能,或者 .resx 文件中的字符串是否已经缓存并且性能“足够”?我缺乏如何处理 .resx 文件的经验,因此您的所有输入都有帮助!

I am trying to model a new site (only on paper so far), and I started to think about what might be the best approach. The site needs to be multi-lingual (at least two languages). Since I recently began testing Redis, I figured that maybe I could store a library of languages in Redis instead of in .resx-files.

I know it's doable, but is it worth it? Is it possible it will increase performance, or are strings in .resx-files already cached and performant "enough"? I lack the experience of how .resx-files are processed, so all your input is of help!

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

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

发布评论

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

评论(1

原谅我要高飞 2025-01-13 02:10:00

我最近在一个多语言网站上工作。
我使用了 Json 字符串。
我在数据库中存储每种语言一个字符串。

{
"HeaderWordWideShipping" : "全球运送/30 天全额退货",
"标头货币" : "货币" ,
"ComboSelectAll" : "选择全部..."
在 Page_Init 上,

我从数据库中选择正确的字符串,并将值分配给公共属性。这里有一些示例代码(我使用 Newtonsoft.Json.dll 来读取 Json):

public string PagetxtHeaderWordWideShipping { get; set; }
public string PagetxtHeaderCurrency { get; set; }
public string ComboSelectAll { get; set; }
string pageTextsMaster = my json string reteived from db

pageTextsMaster = pageTextsMaster ?? @"{"""":""""}"; //if pageTextsMaster isNull then I set an empty Json string.

    JObject o = JObject.Parse(pageTextsMaster);

    PagetxtHeaderWordWideShipping = (string)o.SelectToken("HeaderWordWideShipping", false); //Setting false will not throw an exception if the required value is not found
    PagetxtHeaderCurrency = (string)o.SelectToken("HeaderCurrency"); //false is default so I do not have to repeat it.
    ComboSelectAll = (string)o.SelectToken("ComboSelectAll");

然后您可以在页面中使用公共属性。
为了更加安全,我添加了一个合并运算符来用默认语言文本替换 null:

<h3><%: PagetxtHeaderWordWideShipping ?? "Word Wide Shipping / 30 days Full Return"%></h3>

I have recently worked on a multilingual web site.
I used a Json string.
I'm storing in the database one string per language.

{
"HeaderWordWideShipping" : "Word Wide Shipping / 30 days Full Return",
"HeaderCurrency" : "Currency" ,
"ComboSelectAll" : "Select all..."
}

On Page_Init I select from database the correct string and I assign values to public properties. here some sample code (I used Newtonsoft.Json.dll to read Json):

public string PagetxtHeaderWordWideShipping { get; set; }
public string PagetxtHeaderCurrency { get; set; }
public string ComboSelectAll { get; set; }
string pageTextsMaster = my json string reteived from db

pageTextsMaster = pageTextsMaster ?? @"{"""":""""}"; //if pageTextsMaster isNull then I set an empty Json string.

    JObject o = JObject.Parse(pageTextsMaster);

    PagetxtHeaderWordWideShipping = (string)o.SelectToken("HeaderWordWideShipping", false); //Setting false will not throw an exception if the required value is not found
    PagetxtHeaderCurrency = (string)o.SelectToken("HeaderCurrency"); //false is default so I do not have to repeat it.
    ComboSelectAll = (string)o.SelectToken("ComboSelectAll");

then you can use public propertis in your page.
to be extra safe I added a coalesce operator to replace a null with a default language text:

<h3><%: PagetxtHeaderWordWideShipping ?? "Word Wide Shipping / 30 days Full Return"%></h3>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文