My program doesn't have bugs. It just develops random features.
Legacy:InsertLocalizedString
From Unreal Wiki, The Unreal Engine Documentation Site
Contents
About[edit]
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.
Before[edit]
Note: the | below indicates the current cursor position;
class MyClass extends Object //!localization function DoSomething() { BroadcastMessage(|); }
After[edit]
class MyClass extends Object //!localization var localized string MyLocalisedString; function DoSomething() { BroadcastMessage(MyLocalisedString|); } defaultproperties { MyLocalisedString="This is my localised string" }
Code[edit]
// // InsertLocalizedString - version 1.0 // by Michiel "El Muerte" Hendriks <elmuerte@drunksnipers.com> // // 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;
→ ---