Tnx Bob.
Allthough it’s not the clean code I’d like, it certainly does the trick. Performance improved drastically ![Smile :)]()
for all the people interested, here’s the code. Saves me a lot of time, typing in all the key’s I need. Basically, this code, when run, creates I18N keys for every form, every table and every dataprovider in the table, for a certain Server, a certain Locale and the current solution.
The code relies on a form called applicationtranslation, which is basically a view on your I18N table and a table called languages, in which I store the translations that I want to have available for my solution. The available translations are stored with a start and enddate.
You probably have to fiddle a bit with it to make it work, but it gives a nice idea of what’s possible.
//Configure:
var key_prefix = 'kydome';
var i18n_server = 'Kydome';
//Select Server
var server = plugins.dialogs.showSelectDialog('Select','Select the Server for which you like to create I18N keys:',databaseManager.getServerNames());
if (!server) return;
/* Start Language determination
The Language determination depends on a table called languages,
where available languages for your application are stored with a start and enddate.
If your application doesn't work like this, this part needs to be customized to set the variable "locale" in another way
*/
var maxReturnedRows = 1000;
var query = 'select languagekey from languages where startdate < now() and (enddate is null or enddate > now())';
var dataset = databaseManager.getDataSetByQuery('Kydome', query, null, maxReturnedRows);
var locale = null;
if (dataset.getMaxRowIndex() != 0)
{
var languages = dataset.getColumnAsArray(1);
languages[languages.length] = 'Default';
locale = plugins.dialogs.showSelectDialog('Select','Select the Locale for which you like to create I18N keys:',languages);
if (!locale)
{
return;
}
else if (locale == 'Default')
{
locale = null;
}
}
else
{
var test = plugins.dialogs.showQuestionDialog('Question:','No active languages found. Do you want to create the default keys?','Yes','No');
if(test == 'Yes')
{
locale = null;
}
else
{
return;
}
}
//End Language determination
var tables = databaseManager.getTableNames(server);
var count = 0;
for ( var i = 0 ; i < tables.length ; i++ )
{
query = 'select * from messages where message_key = \''+key_prefix+'.table.'+tables[i]+'\' and message_language = \''+locale+'\'';
dataset = databaseManager.getDataSetByQuery(i18n_server, query, null, maxReturnedRows);
if(dataset.getMaxRowIndex() == 0 )
{
count += 1;
forms.applicationtranslation.controller.newRecord();
forms.applicationtranslation.message_key = key_prefix+'.table.'+tables[i];
forms.applicationtranslation.message_language = locale;
forms.applicationtranslation.message_value = utils.stringInitCap(tables[i]);
forms.applicationtranslation.controller.saveData();
}
var JSTable = databaseManager.getTable(server,tables[i]);
var columns = JSTable.getColumnNames();
for ( var j = 0 ; j < columns.length ; j++ )
{
query = 'select * from messages where message_key = \''+key_prefix+'.dataprovider.'+columns[j]+'\' and message_language = \''+locale+'\'';
dataset = databaseManager.getDataSetByQuery(i18n_server, query, null, maxReturnedRows);
if( dataset.getMaxRowIndex() == 0 )
{
count += 1;
forms.applicationtranslation.controller.newRecord();
forms.applicationtranslation.message_key = key_prefix+'.dataprovider.'+columns[j];
forms.applicationtranslation.message_language = locale;
forms.applicationtranslation.message_value = utils.stringInitCap(columns[j]);
forms.applicationtranslation.controller.saveData();
}
}
}
var formsArray = forms.allnames;
for ( var j = 0 ; j < formsArray.length ; j++ )
{
query = 'select * from messages where message_key = \''+key_prefix+'.form.'+formsArray[j]+'\' and message_language = \''+locale+'\'';
dataset = databaseManager.getDataSetByQuery(i18n_server, query, null, maxReturnedRows);
if( dataset.getMaxRowIndex() == 0 )
{
count += 1;
forms.applicationtranslation.controller.newRecord();
forms.applicationtranslation.message_key = key_prefix+'.form.'+formsArray[j];
forms.applicationtranslation.message_language = locale;
forms.applicationtranslation.message_value = utils.stringInitCap(formsArray[j]);
forms.applicationtranslation.controller.saveData();
}
}
plugins.dialogs.showInfoDialog('Info:','There were '+count+' keys created.','OK');
Enjoy!
Paul