Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Multilingual part strings (or: string to variable)

While trying to translate a project, I got the
following problem:

The message string s
  s:= 'The file ' + fname + ' does not exist';
  ShowMessage(s);
contains two constant strings ('The file ' and
 'does not exist');

The simple way would be to define string ressources or constants, which will be translated separately,
with this result:
  s:= Ressource[currentlanguage,_THE_FILE] + fname +    Ressource[currentlanguage,_DOES_NOT_EXIST];
  ShowMessage(s);

Now I'm looking for a more advanced way (and easier way for the translator) to solve the problem.

E.g. if one could write all parts together into text-files
(one for each language), and parse the language-dependend file, somehow like this:

Textfile:
 FILE_DOES_NOT_EXIST = "The file" + fname + " does not exist";

The constant strings could easily be parsed (e.g. into
a stringlist Parts) and put together.
The problem would be fname, which will be
read as a string, but would have to be converted
into a variable-name. So I would need conversion
from a string to the content of the corresponding
variable name.

s:= Parts[0] + GetVariableContent(Parts[1]) +
    Pars[2];
ShowMessage(s);

Is there any way to achieve this?

Thanks for help,

Gamba



















0
Gamba
Asked:
Gamba
  • 3
  • 3
1 Solution
 
AvonWyssCommented:
Use Format().

s:= Format('The file %s does not exist',[fname]);

Format does also accept multiple parameters and allows to change their order. Therefore this makes it ideal for such tasks.
0
 
GambaAuthor Commented:
No way to convert a string into a variable-name?
0
 
AvonWyssCommented:
Not for common variables, only for components. But trust me, you don't need this and it will work perfectly using Format()! That's what Format() is made for.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
VSFCommented:
I think the best thing to do when creating multiple language app is to use Delphi's native support.
It comes with a wizard that turns to be a best!

Create a new project and click Project >Languages >Add Language on the Delphi main menu!

Hope it helps!

VSF
www.victory.hpg.com.br
www.boatoda.hpg.com.br 
0
 
GambaAuthor Commented:
Ok, Format is a perfect possibilty to solve the
problem. Points for AvonWyss!

Thanks for all comments!

Gamba
0
 
AvonWyssCommented:
Gamba, in order to award me the points, you need to close the question. Thank you, and happy easter!
0
 
GambaAuthor Commented:
Sorry, I tried to, but EE went offline meanwhile.

Gamba
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now