Hi, Kambiz!
Can you explain how to use plural form on same word?
Where add it? How to translate, how to understand plural expressions syntax?
Thanks!
if Screen.MonitorCount = 1 then
TheLabel.Caption := 'You have one monitor'
else
TheLabel.Caption := Format('You have %d monitors', [Screen.MonitorCount]);
if Screen.MonitorCount = 1 then
TheText := Translator.GetText('You have one monitor')
else
TheText := Translator.GetText('You have {0:N0} monitors');
TheLabel.Caption := Localizer.FormatCS(TheText, [Screen.MonitorCount]);
TheText := Translator.GetNText(['You have one monitor', 'You have {0:N0} monitors'], Screen.MonitorCount);
TheLabel.Caption := Localizer.FormatCS(TheText, [Screen.MonitorCount]);
(n == 1) ? 0 : 1
n != 1
n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5
{
TDM - is TDataModule
I using it for translating string resources.
Here is the method for translating plural forms..
}
function TDM.GetTC(aConstId, aCount: Integer): string; overload;
resourcestring
rsTimeCount_Week = 'One week';
rsTimeCount_Weeks = '{0:N0} weeks'; //{0:N0} - What this?
rsTimeCount_Day = 'One day';
rsTimeCount_Days = '{0:N0} days';
rsTimeCount_Hour = 'One hour';
rsTimeCount_Hours = '{0:N0} hours';
rsTimeCount_Min = 'One minute';
rsTimeCount_Mins = '{0:N0} minutes';
rsTimeCount_Sec = 'One second';
rsTimeCount_Secs = '{0:N0} seconds';
begin
Result := '';
case aConstId of
TC_TIMECOUNT_WEEK:
Result := ResTransl.GetNText([rsTimeCount_Week,
rsTimeCount_Weeks], aCount);
TC_TIMECOUNT_DAY:
Result := ResTransl.GetNText([rsTimeCount_Day, rsTimeCount_Days], aCount);
TC_TIMECOUNT_HOUR:
Result := ResTransl.GetNText([rsTimeCount_Hour,
rsTimeCount_Hours], aCount);
TC_TIMECOUNT_MINUTE:
Result := ResTransl.GetNText([rsTimeCount_Min, rsTimeCount_Mins], aCount);
TC_TIMECOUNT_SECOND:
Result := ResTransl.GetNText([rsTimeCount_Sec, rsTimeCount_Secs], aCount);
end;
end;
multilineText := 'First line'#10#13'Second line';
You must pass the result string to Localizer's FormatCS method. In the i18n help look for FormatCS and FormatValue functions to find out about the available formatting options.
n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2
function TDM.GetTC(aConstId, aCount: Integer): string;
resourcestring
rsTimeCount_Day = 'One day';
rsTimeCount_Days = '{0:N0} days';
var
s: string;
begin
Result := '';
case aConstId of
TC_TIMECOUNT_DAY:
begin
s := Translator.GetNText([rsTimeCount_Day, rsTimeCount_Days], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
function TDM.GetTC(aConstId, aCount: Integer): string;
resourcestring
rsTimeCount_Week = 'One week';
rsTimeCount_Weeks = '{0:N0} weeks';
rsTimeCount_Day = 'One day';
rsTimeCount_Days = '{0:N0} days';
rsTimeCount_Hour = 'One hour';
rsTimeCount_Hours = '{0:N0} hours';
rsTimeCount_Min = 'One minute';
rsTimeCount_Mins = '{0:N0} minutes';
rsTimeCount_Sec = 'One second';
rsTimeCount_Secs = '{0:N0} seconds';
var
s: string;
begin
Result := '';
case aConstId of
TC_TIMECOUNT_WEEK:
begin
s := Translator.GetNText([rsTimeCount_Week, rsTimeCount_Weeks], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
TC_TIMECOUNT_DAY:
begin
s := Translator.GetNText([rsTimeCount_Day, rsTimeCount_Days], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
TC_TIMECOUNT_HOUR:
begin
s := Translator.GetNText([rsTimeCount_Hour, rsTimeCount_Hours], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
TC_TIMECOUNT_MINUTE:
begin
s := Translator.GetNText([rsTimeCount_Min, rsTimeCount_Mins], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
TC_TIMECOUNT_SECOND:
begin
s := Translator.GetNText([rsTimeCount_Sec, rsTimeCount_Secs], aCount);
Result := Localizer.FormatCS(s, [aCount]);
end;
end;
end;
Return to DELPHI AREA Projects
Users browsing this forum: No registered users and 2 guests