[i18n] How to translate a unit with constants?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

[i18n] How to translate a unit with constants?

Postby arhangelsoft » July 9th, 2012, 5:17 pm

Hello!

Currently I've a unit with constants, it's looked like this:
Code: Select all
unit GlobalConstsUnit;

interface

resourcestring
  // LOCALIZE
  sBool_True = 'Yes';
  sBool_False = 'No';
  sStatusBar_Status = 'Status: %s';
  sAPB_Enabled = 'Running';
  sAPB_disabled = 'Disabled';
  sAPBOnMutex = 'One instance of this program already is running!' + #10#13 +
    'You can search it:' + #10#13 + '1. On desktop or in taskbar panel' + #10#13
    + '2. In system tray(beside the clocks)' + #10#13 +
    '3. In list of process of "Task Manager"(Press Ctrl+Alt+Del), with name APB.exe';
  sPriority_Lowest = 'Low';
  sPriority_BelowNormal = 'Below normal';
  sPriority_Normal = 'Normal';
  sPriority_AboveNormal = 'Above normal';
  sPriority_High = 'High';
  sPriority_RealTime = 'Real time';
  sOnOffBtn_On = 'Enable';
  sOnOffBtn_Off = 'Disable';
  sAffinityEditMaxDesc = '(Max.: %d )';
  sRuleEditError_MsgBox = 'You made the following errors: ';
  sRuleEditError_1 = '*List of targets is empty';
  sRuleEditError_2 = '*Field "CPU affinity" is empty';
  sAffDesc2fmt =
    '(You can set rsPU numbers from 1 to %d, separated by commas. Set %d for using all CPUs)';
  sNotUsed = 'Not used';
  sTimerStatus_1 = 'All functions disabled!';
  sTimerStatus_2 = 'List of rules is empty!';
  sTrayShowHideBtn_Show = 'Show window';
  sTrayShowHideBtn_Hide = 'Hide window';
  sStatusPanel_Stop = 'Status: Disabled';
  sStatusPanel_Work = 'Status: Running';
  sStatusPanel_StopEx = 'Status: Disabled(%s)';
  sStatusPanel_WorkEx = 'Status: Running(%s)';
  sUnknownProcessUser = '<Unknown Owner>';

implementation

end.


This isn't Form or Data Module, how to translate it?
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: [i18n] How to translate a unit with constants?

Postby geowink » July 10th, 2012, 1:24 pm

Why not a Procedure?

procedure TYourForm.TheProcName(Sender: TObject);
var
sBool_True: string;
< and all the others >
begin

The code goes here

end;

Then use

Public // way at the top of your program
Procedure TheProcName(Sender: TObject);

Is this what you need?

George
George
geowink
Junior Member
Junior Member
 
Posts: 37
Joined: November 29th, 2005, 3:59 am
Location: La Grange, Illinois

Re: [i18n] How to translate a unit with constants?

Postby arhangelsoft » July 10th, 2012, 2:14 pm

Thanks, George!

Many constants are used in multiple units/procedures/сlasses/methods at once. I can not always do so, especially because it will be clutter up the code.

I also remarked that the main form in a module declared a few constants, and they detected by TTranslator. I finished the back all I need constant, but they didn't find by TTranslator. How TTranslator detects these constants, on what basis?

I created a empty form, hid it. I tried to write, and before and after the announcement of form but TTranslator on this empty form, sees nothing.

How can that be:?:
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: [i18n] How to translate a unit with constants?

Postby Kambiz » July 11th, 2012, 3:05 pm

The Pascal parser of i18n package cannot cross-reference string constants in different units and because of that ignores the constants which are not referenced within the same parsing unit. This is why you don't see your constants in the component editor.

Am I going to fix this issue? No, because this is not an issue to me! In my point of view, the developer should use a translatable string constant in the same domain that it is defined, because that string may have different translation in another domain. In addition, this makes the code easier to maintain.

By the way, I do suggest to use a data module instead of a form if you just want to instantiate some non-visual components.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [i18n] How to translate a unit with constants?

Postby arhangelsoft » July 11th, 2012, 5:44 pm

The Pascal parser of i18n package cannot cross-reference string constants in different units and because of that ignores the constants which are not referenced within the same parsing unit. This is why you don't see your constants in the component editor.

I've understand that.

I copy my constants in to new unit with empty form. Drop TTranslator on it, and link it with TLocalizer, Save project files and open TTranslator translations table, it doesn't see defined constants.
Next my step, fully remove project changes(remove all components and unit definitions of i18n package), next I copy me constants to MainForm unit, renew dropping TLocalizer and TTranslator. TTranslator now see only same constants from all of defined(5 of 20 for example), may be is a bug?


I've recorded a video sample demonstration of these bugs(s) in flash format(*.flv).
If you don't have FLV player, you can get it here(permanent link)
Also permanent link to download RAR archive with demo(11,1 Mb).
AVI and other formats is so biggest. FLV more compact.
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk

Re: [i18n] How to translate a unit with constants?

Postby Kambiz » July 12th, 2012, 8:33 pm

It is not a bug. TTranslator only lists the strings that are actually referenced (used) in the code.
If you see a constant is not listed in the list, it means you didn't use that constants somewhere in the unit.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [i18n] How to translate a unit with constants?

Postby arhangelsoft » July 12th, 2012, 8:47 pm

maybe need to make same procedure or class/interface method for manually add constants to localize? Or something else.. like DKLang(http://www.dk-soft.org/index.php?lang=en) constants editor expert..
arhangelsoft
Junior Member
Junior Member
 
Posts: 39
Joined: February 16th, 2012, 9:56 pm
Location: Belarus, Minsk


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron