Recent

Author Topic: resx in lazarus  (Read 5351 times)

addr3ss

  • New Member
  • *
  • Posts: 18
resx in lazarus
« on: July 04, 2015, 11:20:41 am »
Hello!
 I have two questions:
1.How can I use resx files and call strings in them?
2.Does it work on linux systems or only on windows?
tnx

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: resx in lazarus
« Reply #1 on: July 04, 2015, 11:26:52 am »
Hello!
 I have two questions:
1.How can I use resx files and call strings in them?
2.Does it work on linux systems or only on windows?
tnx
You don't resx is .NET only convert to .res or .rc and then you can use them in lazarus both in windows and linux.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: resx in lazarus
« Reply #2 on: July 04, 2015, 11:40:08 am »
You don't resx is .NET only convert to .res or .rc and then you can use them in lazarus both in windows and linux.
You could always go the distance to interpret the internas of a .resx file at runtime,
then you would have the avantage that it works on every system.
But that's a very long shot ...
I go with taazz that there is no direkt, short way to use these files, and it's much better to use .res or .rc files.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

addr3ss

  • New Member
  • *
  • Posts: 18
Re: resx in lazarus
« Reply #3 on: July 04, 2015, 11:43:37 am »
what about android xml?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11457
  • FPC developer.
Re: resx in lazarus
« Reply #4 on: July 04, 2015, 11:50:01 am »
what about android xml?

There are many different kinds of XML on android. Do you mean one aligned to some GUI system maybe?

addr3ss

  • New Member
  • *
  • Posts: 18
Re: resx in lazarus
« Reply #5 on: July 04, 2015, 11:53:09 am »
string xml.for multilingual projects.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: resx in lazarus
« Reply #6 on: July 04, 2015, 12:47:25 pm »
string xml.for multilingual projects.
Generally speaking: XML is always a good idea to store/transfer/retrieve information.
... especially for strings.



OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

addr3ss

  • New Member
  • *
  • Posts: 18
Re: resx in lazarus
« Reply #7 on: July 04, 2015, 12:51:58 pm »
so how can i call strings from xml files?

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: resx in lazarus
« Reply #8 on: July 04, 2015, 01:24:04 pm »
Please make an example.

Normally when you a translation
  you have an speaking identifier like  SHelloWorld  that defaults to 'Hello World !'
So doing the translation you set it to
Code: [Select]
    Language := 'German'
    [...]
    SHelloWorld := GetTranslatedText('SHelloWorld',Language) // Should get you 'Hallo Welt !'
Think also of that texts in different languages have most likely different length. (So leave enough space, have a dynamic layout ...)
For easier maintenance it maybe better to have a file for every language.
So TXMLConfig might be a good solution
http://wiki.freepascal.org/xmlconf

About Internationalization/Localization also read the WiKi:
http://wiki.freepascal.org/Translations_/_i18n_/_localizations_for_programs

PS: when this is related to your 3rdSpace-problem keep in mind that not only the words but also the syntax changes in other languages.
So the first three words of a sentence in one language are not necessary (highly unlikely) the same words in the sentence of another language. Even more when you have idioms.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

addr3ss

  • New Member
  • *
  • Posts: 18
Re: resx in lazarus
« Reply #9 on: July 04, 2015, 01:48:02 pm »
my xml is like this:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
  <resources xmlns:tools="http://schemas.android.com/tools">
    <string name="Tools">Tools-value</string>
    <string name="Settings">Settings-value</string>
    <string name="About">About-value</string>
    <string name="Practice">Practice-value</string>
    <string name="Random Select">RandomSelect-value</string>
</resources>
and i want to call for example 'Tools-value' by its name('Tools').

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: resx in lazarus
« Reply #10 on: July 04, 2015, 02:45:21 pm »
my xml is like this:
[...]
and i want to call for example 'Tools-value' by its name('Tools').
This XML is a little problematic because of the multiple String/Name
If you could live with:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <String>
    <Tools text="Tool-Value"/>
    <Settings text="Settings-Value"/>
    <About text="About-Value"/>
    <Practice text="Practice-Value"/>
    <Random_Select text="Random Select-Value"/>
  </String>
</resources>
(Notice also the '_' of "random select")
the generation code would look like:
Code: [Select]
  xmlRes:=TXMLConfig.Create(nil);
  try
    xmlRes.RootName:='ressource';
    xmlRes.Filename := FDataPath+DirectorySeparator+'English2.xml' ;        // reads the file if it already exists, but...;
    xmlres.Clear;
    xmlres.OpenKey  ('/String') ;
    xmlres.SetValue('Tools/text','Tool-Value');
    xmlres.SetValue('Settings/text','Settings-Value');
    xmlres.SetValue('About/text','About-Value');
    xmlres.SetValue('Practice/text','Practice-Value');
    xmlres.SetValue('Random_Select/text','Random Select-Value');
    xmlres.Flush;
  finally
    FreeAndNil(xmlRes);
  end;
Reading-code looks like this:
Code: [Select]
  xmlRes:=TXMLConfig.Create(nil);
  try
    xmlRes.RootName:='ressource';
    xmlRes.Filename := FDataPath+DirectorySeparator+'English2.xml' ;        // reads the file if it already exists, but...;
    xmlres.OpenKey  ('/String') ;
    writeln(xmlres.getValue('Tools/text','Tools'));
    writeln(xmlres.getValue('Settings/text','Settings'));
    writeln(xmlres.getValue('About/text','About'));
    writeln(xmlres.getValue('Practice/text','Practice'));
    writeln(xmlres.getValue('Random_Select/text','Random Select'));
  finally
    FreeAndNil(xmlRes);
  end;
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

 

TinyPortal © 2005-2018