resourcestrings in pas2js



propertyicon.png resourcestrings - inline

resourcestrings in pas2js are translated to JS objects with original (org) and current value.
Pas2JS pascal source code
unit Unit1; {$mode objfpc} interface uses Classes, SysUtils, JS, Web; resourcestring rsCompiler = 'pas2js'; var s: string; implementation initialization s:= rsCompiler; end.

propertyicon.png resourcestrings - JSON file

The pas2js transpiler can generate a JSON file (extension .jrs) with all the resource strings in your program.

The generating of this file is controlled by the -Jr option. It can take 3 possible arguments:

  1. none This is the default, no file is generated.
  2. unit one file per compiled unit will be generated. This file will contain all resource strings of the unit.
  3. program one file is generated for the main file. This fill will contain all used resource strings for the main file and all the units it uses.
    pas2js -Jrunit unit1.pas -B	
	

The following example has been generated a quite simple file "unit1.jrs".

	
	{
	  "Unit1" : {
		"rsCompiler" : "pas2js"
	  }
	}
	

A JSON object exists for every unit, with each json property a resource string. The following example will generate a file named "project1.jrs" with all the used resource strings in your pas2js program.

    pas2js -Jrprogram project1.lpr -B	
	
{
  "RTLConsts" : {
    "SArgumentMissing" : "Missing argument in format \"%s\"",
    "SInvalidFormat" : "Invalid format specifier : \"%s\"",
    "SInvalidArgIndex" : "Invalid argument index in format: \"%s\"",
    "SListCapacityError" : "List capacity (%s) exceeded.",
    "SListCountError" : "List count (%s) out of bounds.",
    "SListIndexError" : "List index (%s) out of bounds",
    "SSortedListError" : "Operation not allowed on sorted list",
    "SDuplicateString" : "String list does not allow duplicates",
    "SErrFindNeedsSortedList" : "Cannot use find on unsorted list",
    "SInvalidName" : "Invalid component name: \"%s\"",
    "SInvalidBoolean" : "\"%s\" is not a valid boolean.",
    "SDuplicateName" : "Duplicate component name: \"%s\"",
    "SErrInvalidDate" : "Invalid date: \"%s\"",
    "SErrInvalidTimeFormat" : "Invalid time format: \"%s\"",
    "SInvalidDateFormat" : "Invalid date format: \"%s\"",
    "SCantReadPropertyS" : "Cannot read property \"%s\"",
    "SCantWritePropertyS" : "Cannot write property \"%s\"",
    "SErrPropertyNotFound" : "Unknown property: \"%s\"",
    "SIndexedPropertyNeedsParams" : "Indexed property \"%s\" needs parameters",
    "SErrInvalidTypecast" : "Invalid class typecast",
    "SErrInvalidInteger" : "Invalid integer value: \"%s\"",
    "SErrInvalidFloat" : "Invalid floating-point value: \"%s\"",
    "SInvalidDateTime" : "Invalid date-time value: %s",
    "SInvalidCurrency" : "Invalid currency value: %s",
    "SErrInvalidDayOfWeek" : "%d is not a valid day of the week",
    "SErrInvalidTimeStamp" : "Invalid date/timestamp : \"%s\"",
    "SErrInvalidDateWeek" : "%d %d %d is not a valid dateweek",
    "SErrInvalidDayOfYear" : "Year %d does not have a day number %d",
    "SErrInvalidDateMonthWeek" : "Year %d, month %d, Week %d and day %d is not a valid date.",
    "SErrInvalidDayOfWeekInMonth" : "Year %d Month %d NDow %d DOW %d is not a valid date",
    "SInvalidJulianDate" : "%f Julian cannot be represented as a DateTime",
    "SErrInvalidHourMinuteSecMsec" : "%d:%d:%d.%d is not a valid time specification",
    "SInvalidGUID" : "\"%s\" is not a valid GUID value",
    "SEmptyStreamIllegalReader" : "Illegal Nil stream for TReader constructor",
    "SInvalidPropertyValue" : "Invalid value for property",
    "SInvalidImage" : "Invalid stream format",
    "SUnknownProperty" : "Unknown property: \"%s\"",
    "SUnknownPropertyType" : "Unknown property type %d",
    "SAncestorNotFound" : "Ancestor class for \"%s\" not found.",
    "SUnsupportedPropertyVariantType" : "Unsupported property variant type %d",
    "SPropertyException" : "Error reading %s%s%s: %s",
    "SInvalidPropertyPath" : "Invalid property path",
    "SReadOnlyProperty" : "Property is read-only",
    "SClassNotFound" : "Class \"%s\" not found",
    "SEmptyStreamIllegalWriter" : "Illegal Nil stream for TWriter constructor",
    "SErrInvalidPropertyType" : "Invalid property type from streamed property: %d",
    "SParserExpected" : "Wrong token type: %s expected",
    "SParserInvalidFloat" : "Invalid floating point number: %s",
    "SParserInvalidInteger" : "Invalid integer number: %s",
    "SParserUnterminatedString" : "Unterminated string",
    "SParserWrongTokenType" : "Wrong token type: %s expected but %s found",
    "SParserWrongTokenSymbol" : "Wrong token symbol: %s expected but %s found",
    "SParserLocInfo" : " (at %d,%d, stream offset %.8x)",
    "SParserUnterminatedBinValue" : "Unterminated byte value",
    "SParserInvalidProperty" : "Invalid property"
  },
  "Classes" : {
    "SStreamInvalidSeek" : "Seek is not implemented for class %s",
    "SStreamNoReading" : "Stream reading is not implemented for class %s",
    "SStreamNoWriting" : "Stream writing is not implemented for class %s",
    "SReadError" : "Could not read data from stream",
    "SWriteError" : "Could not write data to stream",
    "SMemoryStreamError" : "Could not allocate memory",
    "SerrInvalidStreamSize" : "Invalid Stream size"
  },
  "Unit1" : {
    "rsCompiler" : "pas2js"
  }
}

Of course, this file can be translated, and the translation file can be loaded using the rstranslate unit, part of the rtl. There are demo programs which demonstrate the use of this feature.

Note: that the format is different from the format used by FPC: