Deleting unused Translatable Strings
Posted: Fri Jan 14, 2011 9:48 am
Just thought I would post a method for deleting translatable strings that are not used. Will save a lot of time if you are trying to translate into another language. Hopefully it will help someone at some stage
Code: Select all
constants
Locale_NZ : Integer = 5129;
Percent_Interval : Integer = 2;
vars
crLocale : Locale;
crLocaleNZ : Locale;
crObject : Object;
crSchema : Schema;
crString : TranslatableString;
crStringNZ : TranslatableString;
crStringsNZ : ConstantNDict;
pbAllOk : Boolean;
pbSchemaOk : Boolean;
piCntUnusedSchema : Integer;
piCntUnusedTotal : Integer;
piDone : Integer;
piLastPercentDone : Integer;
piParamCount : Integer;
piParamCountNZ : Integer;
piPercentDone : Integer;
piToDo : Integer;
trLocales : ObjectArray;
trConstants : ConstantSet;
trMethods : MethodSet;
piStart : Integer;
trJcfFile : File;
begin
create trConstants transient;
create trLocales transient;
create trMethods transient;
pbAllOk := true;
crSchema := currentSchema;
piStart := app.clock();
create trJcfFile transient;
trJcfFile.fileName := "c:\Translatable_Strings_To_Delete.jcf";
trJcfFile.usePresentationFileSystem := true;
trJcfFile.mode := File.Mode_Output;
trJcfFile.kind := File.Kind_ANSI;
trJcfFile.shareMode := File.Share_Exclusive;
trJcfFile.open();
trJcfFile.writeLine("JadeCommandFile");
trJcfFile.writeLine("JadeVersionNumber " & app.getSystemVersion());
trJcfFile.writeLine("Commands");
trJcfFile.writeLine("AbortOnError False");
while crSchema <> null do
write Tab & "Checking strings in schema " & crSchema.name;
pbSchemaOk := true;
piCntUnusedSchema := 0;
trLocales.clear();
crSchema.getAllLocalLocales(trLocales);
crLocaleNZ := null;
foreach crObject in trLocales do
crLocale := crObject.Locale;
if crLocale.languageId = Locale_NZ then
crLocaleNZ := crLocale;
break;
endif;
endforeach;
if crLocaleNZ <> null then
crStringsNZ := crLocaleNZ.getTranslatableStrings();
piToDo := crStringsNZ.size();
piDone := 0;
piPercentDone := 0;
piLastPercentDone := 0;
write Tab & Tab & "0%";
foreach crObject in crStringsNZ do
crStringNZ := crObject.TranslatableString;
piParamCountNZ := crStringNZ.getParameterCount();
trMethods.clear();
trConstants.clear();
crStringNZ.getMethodRefs(trMethods);
crStringNZ.getConstantRefs(trConstants);
if trMethods.size() = 0 and trConstants.size() = 0 then
piCntUnusedSchema := piCntUnusedSchema + 1;
//write Tab & Tab & crStringNZ.name & " is NOT used";
trJcfFile.writeLine("Delete TranslatableString " & crSchema.name & "::" & crObject.Constant.name);
endif;
endforeach;
if piPercentDone <> 100 then
write Tab & Tab & "100%";
endif;
else
write Tab & Tab & "Unable to locate locale " & Locale_NZ.String & " for schema " & crSchema.name;
pbSchemaOk := false;
endif;
pbAllOk := pbAllOk and pbSchemaOk;
if piCntUnusedSchema > 0 then
write Tab & Tab & "Schema " & crSchema.name & " contains " & piCntUnusedSchema.String & " unused strings";
endif;
piCntUnusedTotal := piCntUnusedTotal + piCntUnusedSchema;
crSchema := crSchema.superschema;
endwhile;
trJcfFile.close();
write "Time = " & (app.clock() - piStart).String;
write Tab & ">>> A total of " & piCntUnusedTotal.String & " unused strings were detected";
epilog
delete trLocales;
end;