• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

How to read settings and use interpret plugins (sort of)

Started by jep, 2008.04.10, 11:32:01

Previous topic - Next topic

jep

Marked as: Normal
Hello,

The built in function interpret is very powerful and can help you in many situations.

You can use it to create "plugins" and to read settings from ordinary text files.

A drawback with this is that it's possible to add code that you didn't anticipate and can cause unwanted behaviour. But since rexx is an interpreted language in itself I guess you have a decent overview of what each .cmd-file and script does?!  ;)

Note: The code within the plugin can also access global variables in your code and load/unload external packages such as rexxutil!

/* Read settings from a file */

my_global_variable = 'Loading plugin... One moment please!'

say my_global_variable

infile = 'settings.plg'

text = ''
do while lines( infile ) > 0
   text = text';'linein( infile )
end
interpret strip( text,, ';' )

say my_global_variable



Settings/Plugin:
/* settings.plg */

/* Example on how to load external .dll inside the plugin */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

/* This is a comment in rexx */

say 'Reading settings from 'infile
drives = SysDriveMap( 'C:', 'USED' )
do j = 1 to words( drives )
   say 'Searching 'SUBWORD( drives, j, 1 )' for readme.txt'
   call SysFileTree SUBWORD( drives, j, 1 )'\*readme.txt', 'file', 'SFO'
   if file.0 > 0 then do
      say 'Found 'file.1 /* Doesn't display the rest */
      leave j /* Jump out of loop */
   end
end
/* set variable */
my_global_variable = 'Plugin loaded.'

/* Unload external rexx .dll */
call SysDropFuncs

jep

Hello,

it's quite often useful to output messages to the user in the language the user understand and use in every day conversation. Developers of rexx scripts often don't think about writing for more one language and therefore write text right into the code thus making it difficult to understand for all users.

In rexx there are at least 2 ways to use translations, one is to use SysGetMessage together with a compiled message file. Another approach is to create a plain text message and parse the contents. The example provided show how to use a text file with more or less static messages.

/* Read settings from a file */

my_global_variable = 'Loading message file... One moment please!'


infile = 'MyApp_'||value( 'LANG',, 'ENVIRONMENT' )||'.nls'

do while lines( infile ) > 0
  interpret linein( infile )
end
call stream infile, 'C', 'CLOSE'


MyApp_en_US.nls

file.file = '~File'
file.new = '~New'
file.open = '~Open...      Ctrl+O'
file.save = '~Save          F2'
file.saveas = 'Save ~as...'
file.print = '~Print'
file.exit = '~Exit'
help.help = '~Help'
help.index = 'Help ~index'
help.general = '~General help'
help.using = '~Using keys'
help.keys = '~Keys help'
help.commands = '~Commands help'
help.quickref = '~Quick reference'
help.about = '~About...'


MyApp_sv_SE.nls

file.file = '~Fil'
file.new = '~Ny'
file.open = '~Öppna...      Ctrl+O'
file.save = '~Spara          F2'
file.saveas = 'Spar~a som...'
file.print = 'Skriv ~ut'
file.exit = '~Avsluta'
help.help = '~Hjälp'
help.index = 'Hjälp~index'
help.general = '~Generell hjälp'
help.using = '~Använda tangenter'
help.keys = '~Tangenthjälp'
help.commands = '~Kommandohjälp'
help.quickref = 'S~nabbrereferens'
help.about = '~Om...'


Recent efforts within the community has addressed the problem for compiled GUI/PM and VIO (text mode) applications with various formats and approaches. There's no unified way to translate applications that has been widely accepted even though some solutions have been brought forward. Translators have to adjust to the various ways and approaches that may vary quite a lot.

It should be possible to overcome, if "all" text resources are fed into a database in one format first, then translated. It would then be quite easy to export text back to each application afterwards. Developers that use nls resources should then just have to download common messages and add new they want translated.

Online translation services seem to rely on what users contribute and verify correctness of each others work etc. If we'd even have a web based front end for translation that "everyone" could access it would probably mean that we'd get some more apps in more languages.

I've even showed you how to download and use Google translate to fetch words, so it should even be possible to "borrow" translations from them as they get better.

Would you then be willing to translate a sentence each time you visit e.g. OS/2 World?
Would you agree to verify the correctness of another visitors translation?