[Pas2js] resourcestrings structure

Michael Van Canneyt michael at freepascal.org
Fri Aug 9 21:15:34 CEST 2019


That approach only works for when you compile a complete program because the
resource string index is a global hardcoded index. It also means the index
for a given resource string changes with every compiled program, which is
simply bad design.

We have an approach that allows to load units on the fly. (dynamic packages?)
It also means you can translate all strings once: you know them by name and
can keep a translation file which will work accross programs.

The concept has been weighed and thought through, and is not likely to change.

Michael.

On Fri, 9 Aug 2019, warleyalex via Pas2js wrote:

> DWscript translates resourcestring using another approach:
> All resource strings get an index are stored in a global JS-side array named
> "$R". Each time they are accessed, it is through a "$R[index]". This
> approach have the pros and cons, it has less overhead but if if you wish to
> switch language :(
>
> ---------------------------
> { filename: res.pas }
>
> unit res;
>
> uses Classes;
>
> interface
>
> resourcestring
>  SInvalidFormat = '"Invalid format specifier : %s';
>  SDuplicateName =  'Duplicate component name: %s';
>
> implementation
>
> end.
>
> (...)
> ====================
> begin
>  console.log( SInvalidFormat );
>  console.log( SDuplicateName );
> end;
> ***************************************
>
>
>
> JS output:
>
> var $R =
>    ["Missing argument in format %s",
>    "Invalid format specifier : %s",
>    "Invalid argument index in format: %s",
>    "List capacity (%s) exceeded.",
>    "List count (%s) out of bounds.",
>    "List index (%s) out of bounds",
>    "Operation not allowed on sorted list",
>    "String list does not allow duplicates",
>    "Cannot use find on unsorted list",
>    "Invalid component name: %s",
>    "%s is not a valid boolean.",
>    "Duplicate component name: %s",
>    "Invalid date: %s",
>    "Invalid time format: %s",
>    "Invalid date format: %s",
>    "Cannot read property %s",
>    "Cannot write property %s",
>    "Unknown property: %s",
>    "Indexed property %s needs parameters",
>    "Invalid class typecast",
>    "Invalid integer value: %s",
>    "Invalid floating-point value: %s",
>    "Invalid date-time value: %s",
>    "Invalid currency value: %s",
>    "%d is not a valid day of the week",
>    "Invalid date/timestamp : %s",
>    "%d %d %d is not a valid dateweek",
>    "Year %d does not have a day number %d",
>    "Year %d, month %d, Week %d and day %d is not a valid date.",
>    "Year %d Month %d NDow %d DOW %d is not a valid date",
>    "%f Julian cannot be represented as a DateTime",
>    "%d:%d:%d.%d is not a valid time specification",
>    "%s is not a valid GUID value",
>    "Illegal Nil stream for TReader constructor",
>    "Invalid value for property",
>    "Invalid stream format",
>    "Unknown property: %s",
>    "Unknown property type %d",
>    "Ancestor class for %s not found.",
>    "Unsupported property variant type %d",
>    "Error reading %s%s%s: %s",
>    "Invalid property path",
>    "Property is read-only",
>    "Class %s not found",
>    "Illegal Nil stream for TWriter constructor",
>    "Invalid property type from streamed property: %d",
>    "Wrong token type: %s expected",
>    "Invalid floating point number: %s",
>    "Invalid integer number: %s",
>    "Unterminated string",
>    "Wrong token type: %s expected but %s found",
>    "Wrong token symbol: %s expected but %s found",
>    " (at %d,%d, stream offset %.8x)",
>    "Unterminated byte value",
>    "Invalid property",
>    "Seek is not implemented for class %s",
>    "Stream reading is not implemented for class %s",
>    "Stream writing is not implemented for class %s",
>    "Could not read data from stream",
>    "Could not write data to stream",
>    "Could not allocate memory",
>    "Invalid Stream size"];
>
> (...)
> console.log( $R[1] ); // for the key SInvalidFormat
> console.log( $R[11] ); // for the key SDuplicateName
>
>
>
>
> --
> Sent from: http://pas2js.38893.n8.nabble.com/
> _______________________________________________
> Pas2js maillist  -  Pas2js at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js


More information about the Pas2js mailing list