对于 I18N,在代码中存储与表单无关的字符串的位置!

发布于 2024-11-17 12:24:56 字数 110 浏览 3 评论 0原文

我们有一个相对较大的 dotNet 应用程序,并且想知道在代码中存储与表单无关的字符串的最佳位置在哪里?我们不希望在应用程序的解决方案资源管理器窗口中显示数十个未折叠的 resx 文件。任何建议将不胜感激。

We have a relatively large dotNet application and are wondering where is the best place to store strings in our code that aren't related to forms? We don't want to have tens of un-collapse resx file being displayed in our application's solution explorer window. Any advice would be appreciated.

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

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

发布评论

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

评论(3

梦中的蝴蝶 2024-11-24 12:24:56

Android 有一种有趣的方法来做到这一点 - 基本上有一个默认目录,然后为每个其他区域设置一个单独的目录。它看起来非常干净并且可以折叠,因为它们每个都有自己的文件夹。

看一下这里,看看是否值得在之后对代码进行建模:

http://developer .android.com/guide/topics/resources/localization.html

Android has an interesting way of doing it - basically having a default directory, then a separate one for each other locale. It looks pretty clean and would be collapsible since they each have their own folders.

Take a look here and see if it's worth modeling your code after:

http://developer.android.com/guide/topics/resources/localization.html

明明#如月 2024-11-24 12:24:56

我们在输出之前将所有字符串包裹在 i18n() 周围。大多数字符串都在代码中。 i18n 函数将获取字符串和上下文,并在 PO 文件中查找它并返回 i18n 结果,我假设您已经知道这一点。

PERL 示例

## we have this handy noop function for putting strings into a PO file
i18n_noop('Some string that needs to be i18n','This is the context'); 

## once our string has been captured in the PO file, we can assign it to a scalar variable
my $str = 'Some String that needs to be i18n';

## before printing the str we pass it i18n, this function will take the $str and find the appropriate translation.
print i18n($str);

## we could also do this.  The first argument is the string to be translated.  the second argument is the context.
i18n('Some string that needs to be i18n','This is the context'); 

We wrap all strings around i18n() right before output. Most strings are in the code. The i18n function will take the string and context and look it up in a PO file and return the i18n'd result, which I assume you already know that.

A PERL Example

## we have this handy noop function for putting strings into a PO file
i18n_noop('Some string that needs to be i18n','This is the context'); 

## once our string has been captured in the PO file, we can assign it to a scalar variable
my $str = 'Some String that needs to be i18n';

## before printing the str we pass it i18n, this function will take the $str and find the appropriate translation.
print i18n($str);

## we could also do this.  The first argument is the string to be translated.  the second argument is the context.
i18n('Some string that needs to be i18n','This is the context'); 
讽刺将军 2024-11-24 12:24:56

通常人们倾向于为 resx 文件创建简单的源目录。
人们可以创建 LocalizedResources 文件夹并将所有可翻译的 resx 文件放在那里,以及不可翻译的 resx 文件的 NonLocalizedResources (如果您使用它们;在足够大的项目中,您这样做的可能性很高)。

Typically people tend to create simple source directories for resx files.
One can create LocalizableResources folder and place all translatable resx files there, as well as NonLocalizableResources for non-translatable resx files (if you use them; in sufficiently large project chances are high that you do).

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