November 25, 2009 Delphi
November 25, 2009 Delphi
Delphi has a reserved word resourcestring for ensuring that strings allow localization.
resourcestring keyword works like this:
resourcestring
msg=’Hello, World’;
begin
ShowMessage (msg);
end.
Delphi automatically replaces the reference to msg with a call to the system function LoadResString(), which retrieves the string “Hello, World” from the resource part of the executable. The Delphi ITE achieves its translation mechanism by redirecting these fetches to other files.
By including gnugettext.pas in your project, these fetches are replaced with another function, which translates all the strings. The default is, that resourcestrings are translated using the default textdomain, i.e. default.mo. In case you want the system to search other mo files, if the translation isn’t found in default.mo just make some calls to the AddDomainForResourceString.
From this table:
http://www.netcoole.com/delphi2cs/statements.htm
we could see that C# corresponding statement is const string res = “bla-bla string”
At our project we have custom stringresourcetool which is able to generate classes with const strings properties basing on text files at design time in VS.
So next line in *.txt file:
msg=Hello, World
will generate:
public static string msg{get…}
which gets actual string from generated resource file.
When we are talking about resource files for globalization C# has easy way to fetch required strings. We could have files
like YourApplicationResources.uk-UA.resx for Ukrainian culture and so on… So application will be grabbing needed strings from needed files.
Interesting fact on theme:
“NASA’s Mars Climate Orbiter was lost on September 23, 1999 at a cost of $125 million because one engineering team used metric units, while another one used inches for a key spacecraft operation. When writing applications for international distribution, different cultures and regions must be kept in mind.”
Markdown | Result |
---|---|
*text* | text |
**text** | text |
***text*** | text |
`code` | code |
~~~ more code ~~~~ |
more code |
[Link](https://www.example.com) | Link |
* Listitem |
|
> Quote | Quote |
The way you shared your knowledge here is amazing!
Picgrant Singapore 2014