Legacy:InsertLocalizedString

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 04:13, 10 April 2007 by Wormbo (talk | contribs) (reverted once again and locked)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

About

This macro makes it easy to use localized strings. It will prompt for the localized name and the international value of the localized string, it will then find the place where to declare the localized string. For this you will have to add the following comment in your source file:

<uscript> //!localization </uscript>

It will then declare the variable, find the defaultproperties block (create it if it doesn't exist) and add the value to the default properties. finally it will add the variable name to current location.

Before

Note: the | below indicates the current cursor position;

<uscript> class MyClass extends Object

//!localization

function DoSomething() {

 BroadcastMessage(|);

} </uscript>

After

<uscript> class MyClass extends Object

//!localization var localized string MyLocalisedString;

function DoSomething() {

 BroadcastMessage(MyLocalisedString|);

}

defaultproperties {

 MyLocalisedString="This is my localised string"

} </uscript>

Code

<uscript> // // InsertLocalizedString - version 1.0 // by Michiel "El Muerte" Hendriks <[email protected]> // // This macro makes it easy to use localized strings. It will prompt for the // localized name and the international value of the localized string, it will // then find the place where to declare the localized string. For this you // will have to add the following comment in your source file: // //!localization // It will then declare the variable, find the defaultproperties block (create // it if it doesn't exist) and add the value to the default properties. finally // it will add the variable name to current location. //

program InsertLocalizedString begin

   XPos, YPos := CursorXY();
   qres, stringName := InputQuery('Localized string', 'Enter the name of the localized string', );
   if ((stringName = ) or (qres = false)) then exit;
   stringVal := InputBox('Localized string', 'Enter the international value', );
   // find "//!localization" entry
   SetCursorXY(1, 1);
   while (CompareText(CurrentLine(), '//!localization') <> 0) do begin
       DoEditorCommand(ecDown);
       tx, ty := CursorXY();
       if (ty >= LineCount()) then begin
           SetCursorXY(XPos, YPos);
           Beep();
           ShowMessage('Error: no //!localization line found');
           exit;
       end;
   end;
   DoEditorCommand(ecDown);
   DoEditorCommand(ecLineStart);
   bHasLocalizedString := false;
   if (CompareText(CurrentWord(), 'var') = 0) then begin
       DoEditorCommand(ecWordRight);
       if (CompareText(CurrentWord(), 'localized') = 0) then begin
           bHasLocalizedString := true;
           DoEditorCommand(ecLineStart);
       end;
   end;
   if (bHasLocalizedString = false) then begin
       DoEditorCommand(ecInsertLine);
       YPos := YPos+1;
       DoEditorCommand(ecAddString, 'var localized string ;');
       DoEditorCommand(ecLineStart);
   end;
   // find ';'
   while (true) do begin
       DoEditorCommand(ecSelWordRight);
       if (pos(';', SelText()) > 0) then break;
       tx, ty := CursorXY();
       if (ty >= LineCount()) then begin
           ShowMessage('Error: ";" not found');
           exit;
       end;
   end;
   DoEditorCommand(ecLeft);
   if (bHasLocalizedString) then DoEditorCommand(ecAddString, ', ');
   tx, ty := CursorXY();
   // insert a newline
   if (tx >= 80) then begin
       DoEditorCommand(ecInsertLine);
       YPos := YPos+1;
       DoEditorCommand(ecDown);
       DoEditorCommand(ecLineStart);
       DoEditorCommand(ecTab);
   end;
   DoEditorCommand(ecAddString, stringName);
   //DoEditorCommand(ecInsertLine);
   //DoEditorCommand(ecAddString, 'var localized string '+stringName+';');
   // find defaultproperties
   while (CompareText(CurrentLine(), 'defaultproperties') <> 0) do begin
       DoEditorCommand(ecDown);
       tx, ty := CursorXY();
       if (ty >= LineCount()) then begin
           DoEditorCommand(ecInsertLine);
           DoEditorCommand(ecDown);
           DoEditorCommand(ecAddString, 'defaultproperties');
           DoEditorCommand(ecLineBreak);
           DoEditorCommand(ecAddString, '{');
           DoEditorCommand(ecLineBreak);
           DoEditorCommand(ecAddString, '}');
           DoEditorCommand(ecUp);
           DoEditorCommand(ecUp);
           break;
       end;
   end;
   // move to end of defaultproperties block
   DoEditorCommand(ecDown);
   DoEditorCommand(ecLineStart);
   DoEditorCommand(ecMatchBracket);
   DoEditorCommand(ecInsertLine);
   DoEditorCommand(ecTab);
   DoEditorCommand(ecAddString, stringName+'="'+stringVal+'"');
   // restore position
   SetCursorXY(XPos, YPos);
   DoEditorCommand(ecAddString, stringName);

end; </uscript>

→ ---