Skip to content

Commit

Permalink
feat: add i18n hack :squirrel:
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurcio committed Oct 27, 2018
1 parent 1a7b809 commit 4b0187d
Show file tree
Hide file tree
Showing 21 changed files with 1,670 additions and 196 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ buildNumber.properties
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
hs_err_pid*

# i18n hack
**/plugins/*/src/main/java/br/ufrj/ppgi/greco/kettle/messages
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,29 @@ O ``pom.xml`` do filho também precisa ser atualizado para copiar essa dependên
1. Adicionar uma nova dependência ao pom do plugin em ``<dependency>``.
2. Adicionar um ``<artifactItem>`` ao goal ``copy``. Isso vai garantir que a dependência adicionada seja copiada para a pasta lib do plugin.
2. Adicionar um novo ``<replace>`` ao goal ``copy-files-to-kettle``. O replace vai substituir no ``plugin.xml`` o valor da variável ``{dependency.version}`` com o valor que foi colocado no pom do projeto pai em ``${dependency.version}``. Mais informações em [maven-ant-run replace task](https://ant.apache.org/manual/Tasks/replace.html).

## i18n

O Kettle 6+ aparentemente tem um bug no qual a i18n não funciona para múltiplos plugins da forma que o Kettle ensina a fazer a i18n. Para resolver esse problema, existe um hack no qual todos os arquivos properties ``messages_xx_XX.properties`` precisam ser iguais e conter a tradução de TODOS os plugins!

Esse hack foi implementado neste repositório para permitir o uso da i18n da seguinte forma:

1. Ao invés de existir arquivos properties na pasta messages de cada plugin, existe apenas uma pasta messages no parent dos plugins com arquivos properties que contém a tradução de TODOS os plugins;
2. Foi adicionado um ``copy`` no pom do parent para cada plugin que copia essa pasta messages para os filhos:

```
<copy todir="${basedir}/%nome_plugin%/src/main/java" overwrite="true">
<fileset dir="${basedir}/src/main/java" includes="**/*.properties" />
</copy>
```

3. Foi adicionado uma linha no ``.gitignore`` para ignorar a pasta messages dos filhos.

Dessa forma, quando ``mvn clean install`` é executado no parent, o parent copia a pasta messages para todos os filhos antes de buildar os filhos. Assim a i18n funciona para todos os plugins.

### Adiconando uma nova tradução

Para adicionar uma nova tradução é necessário:

1. Adicionar essas traduções nos arquivos .properties no parent;
2. Adicionar um ``copy`` no pom do parent para o seu novo plugin.
13 changes: 13 additions & 0 deletions plugins/Annotator/etc/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@
<library name="Annotator.jar"/>
<library name="lib/KettlePluginTools-1.0.jar"/>
</libraries>

<localized_category>
<category locale="en_US">LinkedDataBR</category>
<category locale="pt_BR">LinkedDataBR</category>
</localized_category>
<localized_description>
<description locale="en_US">Annotator</description>
<description locale="pt_BR">Annotator</description>
</localized_description>
<localized_tooltip>
<tooltip locale="en_US">Generate NTriple format's RDF statements</tooltip>
<tooltip locale="pt_BR">Gera linhas RDF no formato NTriple.</tooltip>
</localized_tooltip>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.swt.widgets.Text;
import org.pentaho.di.core.Const;
import org.pentaho.di.core.util.StringUtil;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
Expand All @@ -37,6 +38,9 @@
*
*/
public class AnnotatorStepDialog extends BaseStepDialog implements StepDialogInterface {

private static Class<?> PKG = AnnotatorStepMeta.class;

private AnnotatorStepMeta input;
private String dialogTitle;

Expand Down Expand Up @@ -72,7 +76,7 @@ public AnnotatorStepDialog(Shell parent, Object stepMeta, TransMeta transMeta, S
input = (AnnotatorStepMeta) baseStepMeta;

// Additional initialization here
dialogTitle = "Anotator";
dialogTitle = BaseMessages.getString(PKG, "AnnotatorStep.Title");
}

public String open() {
Expand Down Expand Up @@ -106,7 +110,7 @@ public void modifyText(ModifyEvent e) {

// Adiciona um label e um input text no topo do dialog shell
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText("Nome do Step");
wlStepname.setText(BaseMessages.getString(PKG, "AnnotatorStep.StepNameField.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
Expand All @@ -125,7 +129,7 @@ public void modifyText(ModifyEvent e) {

// Adiciona label e combo do campo sujeito
wlSubject = new Label(shell, SWT.RIGHT);
wlSubject.setText("Campo Sujeito");
wlSubject.setText(BaseMessages.getString(PKG, "AnnotatorStep.SubjectField.Label"));
props.setLook(wlSubject);
fdlSubject = new FormData();
fdlSubject.left = new FormAttachment(0, 0);
Expand Down Expand Up @@ -156,7 +160,7 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) {

// Adiciona label e combo do campo predicado
wlPredicate = new Label(shell, SWT.RIGHT);
wlPredicate.setText("Campo Predicado");
wlPredicate.setText(BaseMessages.getString(PKG, "AnnotatorStep.PredicateField.Label"));
props.setLook(wlPredicate);
fdlPredicate = new FormData();
fdlPredicate.left = new FormAttachment(0, 0);
Expand Down Expand Up @@ -187,7 +191,7 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) {

// Adiciona label e combo do campo objeto
wlObject = new Label(shell, SWT.RIGHT);
wlObject.setText("Campo Objeto");
wlObject.setText(BaseMessages.getString(PKG, "AnnotatorStep.ObjectField.Label"));
props.setLook(wlObject);
fdlObject = new FormData();
fdlObject.left = new FormAttachment(0, 0);
Expand Down Expand Up @@ -218,7 +222,7 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) {

// Adiciona label e text do campo saida
wlNTriple = new Label(shell, SWT.RIGHT);
wlNTriple.setText("Campo NTriple"); //$NON-NLS-1$
wlNTriple.setText(BaseMessages.getString(PKG, "AnnotatorStep.NTripleField.Label")); //$NON-NLS-1$
props.setLook(wlNTriple);
fdlNTriple = new FormData();
fdlNTriple.left = new FormAttachment(0, 0);
Expand All @@ -238,13 +242,13 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) {

// Bottom buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText("OK"); //$NON-NLS-1$
wOK.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.OK")); //$NON-NLS-1$
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText("Cancelar"); //$NON-NLS-1$
wCancel.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Cancel")); //$NON-NLS-1$
setButtonPositions(new Button[] { wOK, wCancel }, margin, wBrowse);

wlShape = new Label(shell, SWT.RIGHT);
wlShape.setText("Arquivo de mapeamento ");
wlShape.setText(BaseMessages.getString(PKG, "AnnotatorStep.MappingFile.Label"));
props.setLook(wlShape);
fdlShape = new FormData();
fdlShape.left = new FormAttachment(0, 0);
Expand All @@ -255,7 +259,7 @@ public void focusGained(org.eclipse.swt.events.FocusEvent e) {
// Botoes para busca de arquivo
wbBrowse = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbBrowse);
wbBrowse.setText("Buscar...");
wbBrowse.setText(BaseMessages.getString(PKG, "AnnotatorStep.Btn.Browse"));
fdbBrowse = new FormData();
fdbBrowse.right = new FormAttachment(100, 0);
fdbBrowse.top = new FormAttachment(wtNTriple, margin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.util.StringUtil;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDialogInterface;
Expand All @@ -43,6 +44,8 @@
import br.ufrj.ppgi.greco.kettle.plugin.tools.swthelper.SwtHelper;

public class DataCubeStepDialog extends BaseStepDialog implements StepDialogInterface {

private static Class<?> PKG = DataCubeStepMeta.class;

private DataCubeStepMeta input;
private SwtHelper swthlp;
Expand All @@ -69,34 +72,35 @@ public DataCubeStepDialog(Shell parent, Object stepMeta, TransMeta transMeta, St
input = (DataCubeStepMeta) baseStepMeta;
swthlp = new SwtHelper(transMeta, this.props);

dialogTitle = "Data Cube Transformator";
dialogTitle = BaseMessages.getString(PKG, "DataCubeStep.Title");
}

private Control buildContents(Control lastControl, ModifyListener defModListener) {

CTabFolder wTabFolder = swthlp.appendTabFolder(shell, lastControl, 90);
CTabItem item = new CTabItem(wTabFolder, SWT.NONE);

item.setText("Definicao das dimensoes");
item.setText(BaseMessages.getString(PKG, "DataCubeStep.Tab.Dimension"));
Composite cpt = swthlp.appendComposite(wTabFolder, lastControl);
ColumnInfo[] columns = new ColumnInfo[] {
new ColumnInfo("Dimensão", ColumnInfo.COLUMN_TYPE_CCOMBO, this.getFields(), true),
new ColumnInfo("URI da Dimensão \u00A0", ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo("Label da Dimensão", ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo("URI do Tipo se for medida", ColumnInfo.COLUMN_TYPE_TEXT) };
new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Dimension.ColumnA"), ColumnInfo.COLUMN_TYPE_CCOMBO, this.getFields(), true),
new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Dimension.ColumnB"), ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Dimension.ColumnC"), ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Dimension.ColumnD"), ColumnInfo.COLUMN_TYPE_TEXT) };
wDimensionTable = swthlp.appendTableView(cpt, null, columns, defModListener, 98);

item.setControl(cpt);

item = new CTabItem(wTabFolder, SWT.NONE);
item.setText("Definicao dos vocabularios");
item.setText(BaseMessages.getString(PKG, "DataCubeStep.Tab.Vocabulary"));
cpt = swthlp.appendComposite(wTabFolder, lastControl);

columns = new ColumnInfo[] { new ColumnInfo("Prefixo", ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo("URI do vocabulario \u00A0", ColumnInfo.COLUMN_TYPE_TEXT) };
columns = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Vocabulary.ColumnA"), ColumnInfo.COLUMN_TYPE_TEXT),
new ColumnInfo(BaseMessages.getString(PKG, "DataCubeStep.Tab.Vocabulary.ColumnB"), ColumnInfo.COLUMN_TYPE_TEXT) };
wVocabularyTable = swthlp.appendTableView(cpt, null, columns, defModListener, 90);

swthlp.appendButtonsRow(cpt, wVocabularyTable, new String[] { "Clear", "Defaults" },
swthlp.appendButtonsRow(cpt, wVocabularyTable, new String[] { BaseMessages.getString(PKG, "DataCubeStep.Btn.Clear"),
BaseMessages.getString(PKG, "DataCubeStep.Btn.Default") },
new SelectionListener[] { new SelectionListener() {

public void widgetSelected(SelectionEvent arg0) {
Expand All @@ -122,7 +126,7 @@ public void widgetDefaultSelected(SelectionEvent arg0) {
item.setControl(cpt);

item = new CTabItem(wTabFolder, SWT.NONE);
item.setText("Campos de saída");
item.setText(BaseMessages.getString(PKG, "DataCubeStep.Tab.Output") );
cpt = swthlp.appendComposite(wTabFolder, lastControl);
/*wKeepInputFields = swthlp.appendCheckboxRow(cpt, null, "Repassar campos de entrada para saída",
new SelectionListener() {
Expand All @@ -134,7 +138,7 @@ public void widgetSelected(SelectionEvent e) {
input.setChanged(true);
}
});*/
wDataCubeOutputFieldName = swthlp.appendTextVarRow(cpt, null, "Campo de saída", defModListener);
wDataCubeOutputFieldName = swthlp.appendTextVarRow(cpt, null, BaseMessages.getString(PKG, "DataCubeStep.Tab.Output.Field") , defModListener);
item.setControl(cpt);

wTabFolder.setSelection(0);
Expand Down Expand Up @@ -204,7 +208,7 @@ public void modifyText(ModifyEvent e) {

// Adiciona um label e um input text no topo do dialog shell
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText("Data Cube Transformation");
wlStepname.setText(BaseMessages.getString(PKG, "DataCubeStep.StepNameField.Label"));
props.setLook(wlStepname);

fdlStepname = new FormData();
Expand All @@ -230,9 +234,9 @@ public void modifyText(ModifyEvent e) {

// Bottom buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText("OK"); //$NON-NLS-1$
wOK.setText(BaseMessages.getString(PKG, "DataCubeStep.Btn.OK")); //$NON-NLS-1$
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText("Cancel"); //$NON-NLS-1$
wCancel.setText(BaseMessages.getString(PKG, "DataCubeStep.Btn.Cancel")); //$NON-NLS-1$
setButtonPositions(new Button[] { wOK, wCancel }, margin, lastControl);

// Add listeners
Expand Down
Loading

0 comments on commit 4b0187d

Please sign in to comment.