diff options
31 files changed, 316 insertions, 283 deletions
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java index 24a8ff15392..cad1b96cbc3 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.duplicationsviewer.client; +import com.google.gwt.i18n.client.Dictionary; import org.sonar.gwt.Metrics; import org.sonar.gwt.ui.DefaultSourcePanel; import org.sonar.gwt.ui.ExpandCollapseLink; @@ -102,13 +103,14 @@ public class DuplicationsPanel extends Composite { } private FlexTable getDuplicationsTable() { + Dictionary l10n = Dictionary.getDictionary("l10n"); FlexTable table = new FlexTable(); table.setStylePrimaryName("duplicationsTable"); table.setText(0, 0, ""); - table.setText(0, 1, "Nb lines"); - table.setText(0, 2, "From line"); - table.setText(0, 3, "File"); - table.setText(0, 4, "From line"); + table.setText(0, 1, l10n.get("dupl.colSize")); + table.setText(0, 2, l10n.get("dupl.colFromLine")); + table.setText(0, 3, l10n.get("dupl.colFile")); + table.setText(0, 4, l10n.get("dupl.colFromLine")); table.getCellFormatter().getElement(0, 0).setId("expandCollapseCol"); table.getCellFormatter().getElement(0, 1).setId("nbLineCol"); diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java index cf44ad88b25..db313329cee 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsViewer.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.duplicationsviewer.client; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Panel; @@ -59,9 +60,10 @@ public class DuplicationsViewer extends Page { addBigCell(panel, measure.getFormattedValue()); } - addCell(panel, getDefaultMeasure(resource, Metrics.LINES, "lines")); - addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_LINES, "Duplicated lines")); - addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_BLOCKS, "Duplicated blocks")); + Dictionary l10n = Dictionary.getDictionary("l10n"); + addCell(panel, getDefaultMeasure(resource, Metrics.LINES, l10n.get("lines"))); + addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_LINES, l10n.get("duplicated_lines"))); + addCell(panel, getDefaultMeasure(resource, Metrics.DUPLICATED_BLOCKS, l10n.get("duplicated_blocks"))); } private Measure getDefaultMeasure(Resource resource, String metric, String label) { diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/GwtHotspots.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/GwtHotspots.java index c4cd86ba5dc..f0adee74dbc 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/GwtHotspots.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/GwtHotspots.java @@ -20,6 +20,7 @@ package org.sonar.plugins.core.hotspots.client; import com.google.gwt.gen2.table.override.client.Grid; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; import org.sonar.gwt.Metrics; @@ -46,16 +47,17 @@ public class GwtHotspots extends Page { VerticalPanel column2 = new VerticalPanel(); column2.setStyleName("hotspotcol"); + Dictionary l10n = Dictionary.getDictionary("l10n"); column1.add(new MostViolatedRules(resource)); - column1.add(new MetricHotspot(resource, Metrics.TEST_EXECUTION_TIME, I18nConstants.INSTANCE.titleLongestTests())); - column1.add(new MetricHotspot(resource, Metrics.COMPLEXITY, I18nConstants.INSTANCE.titleMostComplexResources())); - column1.add(new MetricHotspot(resource, Metrics.DUPLICATED_LINES, I18nConstants.INSTANCE.titleMostDuplicatedResources())); + column1.add(new MetricHotspot(resource, Metrics.TEST_EXECUTION_TIME, l10n.get("hotspot.titleLongestTests"))); + column1.add(new MetricHotspot(resource, Metrics.COMPLEXITY, l10n.get("hotspot.titleMostComplexResources"))); + column1.add(new MetricHotspot(resource, Metrics.DUPLICATED_LINES, l10n.get("hotspot.titleMostDuplicatedResources"))); column1.add(new MostBadlyDesignedFiles(resource)); column2.add(new MostViolatedResources(resource)); - column2.add(new MetricHotspot(resource, Metrics.UNCOVERED_LINES, I18nConstants.INSTANCE.titleLessTested())); - column2.add(new MetricHotspot(resource, Metrics.FUNCTION_COMPLEXITY, I18nConstants.INSTANCE.titleMostComplexMethods())); - column2.add(new MetricHotspot(resource, Metrics.PUBLIC_UNDOCUMENTED_API, I18nConstants.INSTANCE.titleMostUndocumentedAPI())); + column2.add(new MetricHotspot(resource, Metrics.UNCOVERED_LINES, l10n.get("hotspot.titleLessTested"))); + column2.add(new MetricHotspot(resource, Metrics.FUNCTION_COMPLEXITY, l10n.get("hotspot.titleMostComplexMethods"))); + column2.add(new MetricHotspot(resource, Metrics.PUBLIC_UNDOCUMENTED_API, l10n.get("hotspot.titleMostUndocumentedAPI"))); grid.setWidget(0, 0, column1); grid.setWidget(0, 1, column2); diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/I18nConstants.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/I18nConstants.java deleted file mode 100644 index ac1ebd5ab0d..00000000000 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/I18nConstants.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.hotspots.client; - -import com.google.gwt.core.client.GWT; - -public interface I18nConstants extends com.google.gwt.i18n.client.Constants { - - static I18nConstants INSTANCE = GWT.create(I18nConstants.class); - - @DefaultStringValue("Most violated rules") - String titleMostViolatedRules(); - - @DefaultStringValue("Most violated") - String titleMostViolatedResources(); - - @DefaultStringValue("Longest unit tests") - String titleLongestTests(); - - @DefaultStringValue("Highest complexity") - String titleMostComplexResources(); - - @DefaultStringValue("Highest duplications") - String titleMostDuplicatedResources(); - - @DefaultStringValue("Highest untested lines") - String titleLessTested(); - - @DefaultStringValue("Highest average method complexity") - String titleMostComplexMethods(); - - @DefaultStringValue("Most undocumented APIs") - String titleMostUndocumentedAPI(); - - @DefaultStringValue("No measures") - String noMeasures(); - - @DefaultStringValue("Any severity") - String anySeverity(); - - @DefaultStringValue("more") - String moreDetails(); - - @DefaultStringValue("Lack of Cohesion of Methods") - String lcom4(); - - @DefaultStringValue("Response for class") - String rfc(); - - @DefaultStringValue("Highest") - String designTitle(); -} diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/AbstractHotspot.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/AbstractHotspot.java index fa84185c303..aa0426dcbcb 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/AbstractHotspot.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/AbstractHotspot.java @@ -21,11 +21,11 @@ package org.sonar.plugins.core.hotspots.client.widget; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; import org.sonar.gwt.ui.Loading; -import org.sonar.plugins.core.hotspots.client.I18nConstants; import org.sonar.wsclient.services.Measure; import org.sonar.wsclient.services.Resource; @@ -74,7 +74,7 @@ public abstract class AbstractHotspot extends Composite { protected void renderEmptyResults() { Grid grid = new Grid(1, 1); - grid.setWidget(0, 0, new HTML(I18nConstants.INSTANCE.noMeasures())); + grid.setWidget(0, 0, new HTML(Dictionary.getDictionary("l10n").get("hotspot.noMeasures"))); grid.getCellFormatter().setStyleName(0, 0, getRowCssClass(0) + " emptyResultsCell"); grid.setStyleName("gwt-Hotspot"); render(grid); diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MetricHotspot.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MetricHotspot.java index bb19d263d0c..bb3ac53b6de 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MetricHotspot.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MetricHotspot.java @@ -21,10 +21,10 @@ package org.sonar.plugins.core.hotspots.client.widget; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; -import org.sonar.plugins.core.hotspots.client.I18nConstants; import org.sonar.wsclient.gwt.AbstractListCallback; import org.sonar.wsclient.gwt.Sonar; import org.sonar.wsclient.services.Measure; @@ -47,10 +47,11 @@ public class MetricHotspot extends AbstractHotspot { @Override Widget createHeader() { + Dictionary l10n = Dictionary.getDictionary("l10n"); final Label label = new Label(title); label.setStyleName("header"); - final Anchor moreLink = new Anchor(I18nConstants.INSTANCE.moreDetails()); + final Anchor moreLink = new Anchor(l10n.get("hotspot.moreDetails")); moreLink.getElement().setId("more-" + metric); moreLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostBadlyDesignedFiles.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostBadlyDesignedFiles.java index df84f197d49..954effd1362 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostBadlyDesignedFiles.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostBadlyDesignedFiles.java @@ -23,10 +23,10 @@ import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; -import org.sonar.plugins.core.hotspots.client.I18nConstants; import org.sonar.wsclient.gwt.AbstractListCallback; import org.sonar.wsclient.gwt.Sonar; import org.sonar.wsclient.services.Measure; @@ -45,9 +45,10 @@ public class MostBadlyDesignedFiles extends AbstractHotspot { @Override Widget createHeader() { + Dictionary l10n = Dictionary.getDictionary("l10n"); metricSelectBox = new ListBox(false); - metricSelectBox.addItem(I18nConstants.INSTANCE.lcom4(), "lcom4"); - metricSelectBox.addItem(I18nConstants.INSTANCE.rfc(), "rfc"); + metricSelectBox.addItem(l10n.get("hotspot.lcom4"), "lcom4"); + metricSelectBox.addItem(l10n.get("hotspot.rfc"), "rfc"); metricSelectBox.setStyleName("small"); metricSelectBox.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { @@ -55,10 +56,10 @@ public class MostBadlyDesignedFiles extends AbstractHotspot { } }); - final Label label = new Label(I18nConstants.INSTANCE.designTitle()); + final Label label = new Label(l10n.get("hotspot.designTitle")); label.setStyleName("header"); - final Anchor moreLink = new Anchor(I18nConstants.INSTANCE.moreDetails()); + final Anchor moreLink = new Anchor(l10n.get("hotspot.moreDetails")); moreLink.getElement().setId("more-design"); moreLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedResources.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedResources.java index d523bc13b4f..feff7db5e35 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedResources.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedResources.java @@ -21,12 +21,12 @@ package org.sonar.plugins.core.hotspots.client.widget; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; import org.sonar.gwt.Metrics; import org.sonar.gwt.ui.Icons; -import org.sonar.plugins.core.hotspots.client.I18nConstants; import org.sonar.wsclient.gwt.AbstractListCallback; import org.sonar.wsclient.gwt.Sonar; import org.sonar.wsclient.services.Measure; @@ -44,10 +44,11 @@ public class MostViolatedResources extends AbstractHotspot { @Override Widget createHeader() { - final Label label = new Label(I18nConstants.INSTANCE.titleMostViolatedResources()); + Dictionary l10n = Dictionary.getDictionary("l10n"); + final Label label = new Label(l10n.get("hotspot.titleMostViolatedResources")); label.setStyleName("header"); - final Anchor moreLink = new Anchor(I18nConstants.INSTANCE.moreDetails()); + final Anchor moreLink = new Anchor(l10n.get("hotspot.moreDetails")); moreLink.getElement().setId("more-violated-resources"); moreLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedRules.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedRules.java index c58b018a6eb..44d08372033 100644 --- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedRules.java +++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/hotspots/client/widget/MostViolatedRules.java @@ -23,12 +23,12 @@ import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; import org.sonar.gwt.Metrics; import org.sonar.gwt.ui.Icons; -import org.sonar.plugins.core.hotspots.client.I18nConstants; import org.sonar.wsclient.gwt.AbstractCallback; import org.sonar.wsclient.gwt.Sonar; import org.sonar.wsclient.services.Measure; @@ -45,8 +45,9 @@ public class MostViolatedRules extends AbstractHotspot { @Override Widget createHeader() { + Dictionary l10n = Dictionary.getDictionary("l10n"); severity = new ListBox(false); - severity.addItem(I18nConstants.INSTANCE.anySeverity(), ""); + severity.addItem(l10n.get("hotspot.anySeverity"), ""); severity.addItem("Blocker", "BLOCKER"); severity.addItem("Critical", "CRITICAL"); severity.addItem("Major", "MAJOR"); @@ -59,10 +60,10 @@ public class MostViolatedRules extends AbstractHotspot { } }); - final Label label = new Label(I18nConstants.INSTANCE.titleMostViolatedRules()); + final Label label = new Label(l10n.get("hotspot.titleMostViolatedRules")); label.setStyleName("header"); - final Anchor moreLink = new Anchor(I18nConstants.INSTANCE.moreDetails()); + final Anchor moreLink = new Anchor(l10n.get("hotspot.moreDetails")); moreLink.getElement().setId("more-rules"); moreLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/DependenciesTable.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/DependenciesTable.java index ce4ed84c755..b00726c1830 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/DependenciesTable.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/DependenciesTable.java @@ -21,6 +21,7 @@ package org.sonar.plugins.design.ui.dependencies.client; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; import org.sonar.gwt.ui.Icons; @@ -43,7 +44,7 @@ public class DependenciesTable extends Composite { panel.add(createIncomingColumn(data)); panel.add(createOutgoingColumn(data)); } else { - panel.add(new Label(I18nConstants.INSTANCE.noData())); + panel.add(new Label(Dictionary.getDictionary("l10n").get("noData"))); } } @@ -51,7 +52,7 @@ public class DependenciesTable extends Composite { private Panel createIncomingColumn(Data data) { FlexTable grid = new FlexTable(); grid.setStyleName("col"); - grid.setWidget(0, 1, new HTML("<b>" + I18nConstants.INSTANCE.afferentCouplings() + "</b>: " + data.getResource().getMeasureIntValue("ca"))); + grid.setWidget(0, 1, new HTML("<b>" + Dictionary.getDictionary("l10n").get("depsTab.afferentCouplings") + "</b>: " + data.getResource().getMeasureIntValue("ca"))); grid.getRowFormatter().setStyleName(0, "coltitle"); int row = 1; @@ -69,7 +70,7 @@ public class DependenciesTable extends Composite { private Panel createOutgoingColumn(Data data) { FlexTable grid = new FlexTable(); grid.setStyleName("col"); - grid.setWidget(0, 1, new HTML("<b>" + I18nConstants.INSTANCE.efferentCouplings() + "</b>: " + data.getResource().getMeasureIntValue("ce"))); + grid.setWidget(0, 1, new HTML("<b>" + Dictionary.getDictionary("l10n").get("depsTab.efferentCouplings") + "</b>: " + data.getResource().getMeasureIntValue("ce"))); grid.getRowFormatter().setStyleName(0, "coltitle"); int row = 1; diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/Header.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/Header.java index 3be4f7037a5..d902504cb0b 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/Header.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/Header.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.design.ui.dependencies.client; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.*; import org.sonar.wsclient.services.Measure; import org.sonar.wsclient.services.Resource; @@ -49,17 +50,18 @@ public class Header extends Composite { header.clear(); HorizontalPanel panel = new HorizontalPanel(); header.add(panel); - addMeasure(panel, data.getResource(), "classes", I18nConstants.INSTANCE.classes()); - addMeasure(panel, data.getResource(), "dit", I18nConstants.INSTANCE.dit()); - addMeasure(panel, data.getResource(), "noc", I18nConstants.INSTANCE.noc()); - addMeasure(panel, data.getResource(), "rfc", I18nConstants.INSTANCE.rfc()); + Dictionary l10n = Dictionary.getDictionary("l10n"); + addMeasure(panel, data.getResource(), "classes", l10n.get("depsTab.classes")); + addMeasure(panel, data.getResource(), "dit", l10n.get("depsTab.dit")); + addMeasure(panel, data.getResource(), "noc", l10n.get("depsTab.noc")); + addMeasure(panel, data.getResource(), "rfc", l10n.get("depsTab.rfc")); addLcom4(data, panel); } private void addLcom4(Data data, HorizontalPanel panel) { Measure lcom4 = data.getResource().getMeasure("lcom4"); if (lcom4 != null && lcom4.getIntValue()!=null) { - HTML html = new HTML(I18nConstants.INSTANCE.lcom4() + ": "); + HTML html = new HTML(Dictionary.getDictionary("l10n").get("depsTab.lcom4") + ": "); html.setStyleName("metric"); panel.add(html); diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/I18nConstants.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/I18nConstants.java deleted file mode 100644 index cccb2304629..00000000000 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/dependencies/client/I18nConstants.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.design.ui.dependencies.client; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.Constants; - -public interface I18nConstants extends com.google.gwt.i18n.client.Constants { - - static I18nConstants INSTANCE = GWT.create(I18nConstants.class); - - @DefaultStringValue("Afferent (incoming) couplings") - String afferentCouplings(); - - @DefaultStringValue("Efferent (outgoing) couplings") - String efferentCouplings(); - - @DefaultStringValue("Classes") - String classes(); - - @DefaultStringValue("Depth in Tree") - String dit(); - - @DefaultStringValue("Number of Children") - String noc(); - - @Constants.DefaultStringValue("Response for Class") - String rfc(); - - @DefaultStringValue("Lack of Cohesion of Methods") - String lcom4(); - - @DefaultStringValue("No data") - String noData(); -} diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java index 7fe67a1a030..b9aaba09578 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/lcom4/client/Lcom4Tab.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.design.ui.lcom4.client; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.ui.Icons; import org.sonar.gwt.ui.Loading; @@ -87,7 +88,7 @@ public class Lcom4Tab extends Page { header.setStyleName("gwt-ViewerHeader"); HorizontalPanel panel = new HorizontalPanel(); - HTML html = new HTML("Lack of Cohesion of Methods: "); + HTML html = new HTML(Dictionary.getDictionary("l10n").get("lcom4.metric") + ": "); html.setStyleName("metric"); panel.add(html); diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/Filters.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/Filters.java index 6a76d5c681e..ca097a57421 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/Filters.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/Filters.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.design.ui.libraries.client; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.CheckBox; import com.google.gwt.user.client.ui.Grid; @@ -42,21 +43,22 @@ public class Filters extends Grid { super(1, 5); setStyleName("libFilter"); + Dictionary l10n = Dictionary.getDictionary("l10n"); keywordFilter = new KeywordFilter(); - setWidget(0, 0, new Label(I18nConstants.INSTANCE.filter())); + setWidget(0, 0, new Label(l10n.get("libs.filter"))); setWidget(0, 1, keywordFilter); - testCheckbox = new CheckBox(I18nConstants.INSTANCE.displayTests()); + testCheckbox = new CheckBox(l10n.get("libs.displayTests")); testCheckbox.getElement().setId("testCb"); testCheckbox.setValue(Boolean.valueOf(Configuration.getRequestParameter(PARAM_TEST, "false"))); setWidget(0, 2, testCheckbox); - expandCollapse = new Anchor(I18nConstants.INSTANCE.collapse()); + expandCollapse = new Anchor(l10n.get("libs.collapse")); isExpanded = true; setWidget(0, 3, expandCollapse); - usageLink = new Anchor(I18nConstants.INSTANCE.usageLink(), Links.baseUrl() + "/dependencies/index?search=" + resource.getKey()); + usageLink = new Anchor(l10n.get("libs.usageLink"), Links.baseUrl() + "/dependencies/index?search=" + resource.getKey()); setWidget(0, 4, usageLink); } @@ -98,14 +100,14 @@ public class Filters extends Grid { public void expand() { if (!isExpanded) { - expandCollapse.setText(I18nConstants.INSTANCE.collapse()); + expandCollapse.setText(Dictionary.getDictionary("l10n").get("libs.collapse")); isExpanded = true; } } public void collapse() { if (isExpanded) { - expandCollapse.setText(I18nConstants.INSTANCE.expand()); + expandCollapse.setText(Dictionary.getDictionary("l10n").get("libs.expand")); isExpanded = false; } } diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/I18nConstants.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/I18nConstants.java deleted file mode 100644 index 79eecaffdf1..00000000000 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/I18nConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.design.ui.libraries.client; - -import com.google.gwt.core.client.GWT; - -public interface I18nConstants extends com.google.gwt.i18n.client.Constants { - - static I18nConstants INSTANCE = GWT.create(I18nConstants.class); - - @DefaultStringValue("Filter:") - String filter(); - - @DefaultStringValue("Display test libraries") - String displayTests(); - - @DefaultStringValue("Expand all") - String expand(); - - @DefaultStringValue("Collapse all") - String collapse(); - - @DefaultStringValue("No libraries") - String noLibraries(); - - @DefaultStringValue("Usages") - String usageLink(); -} diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java index 685b5ef21c0..56a2b2e59dd 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.design.ui.libraries.client; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.ui.Icons; import org.sonar.gwt.ui.Loading; @@ -101,7 +102,7 @@ public class ProjectPanel extends FlowPanel { } private Label createNoLibsMessage() { - Label msg = new Label(I18nConstants.INSTANCE.noLibraries()); + Label msg = new Label(Dictionary.getDictionary("l10n").get("libs.noLibraries")); msg.setStyleName("nolibs"); return msg; } diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/DependencyInfo.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/DependencyInfo.java index 42db5030b05..22047918857 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/DependencyInfo.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/DependencyInfo.java @@ -21,6 +21,7 @@ package org.sonar.plugins.design.ui.page.client; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Configuration; @@ -95,7 +96,7 @@ public class DependencyInfo extends Composite { protected void doOnResponse(Dependency dependency) { if (dependency == null) { setLoaded(); - panel.add(new Label(I18nConstants.INSTANCE.noData())); + panel.add(new Label(Dictionary.getDictionary("l10n").get("noData"))); } else { loadSubDependencies(dependency); } @@ -168,7 +169,7 @@ public class DependencyInfo extends Composite { } private Widget createNewWindowLink() { - Label popup = new Label(I18nConstants.INSTANCE.newWindow()); + Label popup = new Label(Dictionary.getDictionary("l10n").get("newWindow")); popup.setStyleName("newwindow"); popup.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/Dsm.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/Dsm.java index 6594f9dbf25..5506ec1e35e 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/Dsm.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/Dsm.java @@ -23,6 +23,7 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DoubleClickEvent; import com.google.gwt.event.dom.client.DoubleClickHandler; +import com.google.gwt.i18n.client.Dictionary; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.*; import org.sonar.gwt.Links; @@ -67,25 +68,26 @@ public class Dsm extends Composite { } private Widget createLegend() { + Dictionary l10n = Dictionary.getDictionary("l10n"); HorizontalPanel legend = new HorizontalPanel(); legend.getElement().setId("dsmlegend"); legend.add(new HTML("<div class='square gray'> </div>")); - legend.add(new Label(I18nConstants.INSTANCE.legendDependencies())); + legend.add(new Label(l10n.get("design.legend.dependencies"))); legend.add(new HTML("<div class='space'></div>")); legend.add(new HTML("<div class='square red'> </div> ")); - legend.add(new Label(I18nConstants.INSTANCE.legendCycles())); + legend.add(new Label(l10n.get("design.legend.cycles"))); legend.add(new HTML(" <div class='space'></div> ")); legend.add(new HTML("<div class='square green'></div> ")); - legend.add(new Label(I18nConstants.INSTANCE.legendUses())); + legend.add(new Label(l10n.get("design.legend.uses"))); legend.add(new HTML("<div class='square blue'></div> ")); - legend.add(new Label(I18nConstants.INSTANCE.legendUses())); + legend.add(new Label(l10n.get("design.legend.uses"))); legend.add(new HTML(" <div class='square yellow'></div>")); return legend; } public void displayNoData() { dsm.clear(); - dsm.add(new Label(I18nConstants.INSTANCE.noData())); + dsm.add(new Label(Dictionary.getDictionary("l10n").get("noData"))); } public void display(DsmData.Rows data) { @@ -107,7 +109,8 @@ public class Dsm extends Composite { private Widget createHelp() { HorizontalPanel help = new HorizontalPanel(); help.getElement().setId("dsmhelp"); - Anchor link = new Anchor(I18nConstants.INSTANCE.linkToHelp(), "http://docs.codehaus.org/x/QQFhC", "docsonar"); + Dictionary l10n = Dictionary.getDictionary("l10n"); + Anchor link = new Anchor(l10n.get("design.help"), "http://docs.codehaus.org/x/QQFhC", "docsonar"); help.add(Icons.get().help().createImage()); help.add(link); return help; @@ -289,7 +292,7 @@ public class Dsm extends Composite { cell = buildCell(row, col, weight, (col > row ? GRID_CELL_TOP_RIGHT : GRID_CELL_BOTTOM_LEFT)); if (weight > 0) { - String tooltip = data.get(col).getName() + " -> " + data.get(row).getName() + " (" + weight + "). " + I18nConstants.INSTANCE.cellTooltip(); + String tooltip = data.get(col).getName() + " -> " + data.get(row).getName() + " (" + weight + "). " + Dictionary.getDictionary("l10n").get("design.cellTooltip"); cell.setTitle(tooltip); } return cell; @@ -323,7 +326,7 @@ public class Dsm extends Composite { } }; title.setStylePrimaryName(HEADER_TITLE); - title.setTitle(I18nConstants.INSTANCE.rowTooltip()); + title.setTitle(Dictionary.getDictionary("l10n").get("design.rowTooltip")); final int finalIndexRow = indexRow; title.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/I18nConstants.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/I18nConstants.java deleted file mode 100644 index 48dc7ac6ad2..00000000000 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/page/client/I18nConstants.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.design.ui.page.client; - -import com.google.gwt.core.client.GWT; - -public interface I18nConstants extends com.google.gwt.i18n.client.Constants { - - static I18nConstants INSTANCE = GWT.create(I18nConstants.class); - - @DefaultStringValue("Dependency") - String legendDependencies(); - - @DefaultStringValue("Suspect dependency (cycle)") - String legendCycles(); - - @DefaultStringValue("- uses >") - String legendUses(); - - @DefaultStringValue("No data") - String noData(); - - @DefaultStringValue("New window") - String newWindow(); - - @DefaultStringValue("Click to highlight, double-click to display more details.") - String cellTooltip(); - - @DefaultStringValue("Click to highlight, double-click to zoom.") - String rowTooltip(); - - @DefaultStringValue("Help") - String linkToHelp(); -} diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties index ba9f2dfe8cd..b5b2ae3815a 100644 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -293,8 +293,13 @@ violations_drilldown.page=Violations drilldown update_center.page=Update Center email_configuration.page=Email configuration +# GWT pages org.sonar.plugins.core.hotspots.GwtHotspots.page=Hotspots org.sonar.plugins.core.duplicationsviewer.DuplicationsViewer.page=Duplications +org.sonar.plugins.design.ui.page.DesignPage.page=Design +org.sonar.plugins.design.ui.libraries.LibrariesPage.page=Libraries +org.sonar.plugins.design.ui.dependencies.DependenciesTab.page=Dependencies +org.sonar.plugins.design.ui.lcom4.Lcom4Tab.page=LCOM4 #------------------------------------------------------------------------------ diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/design.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/design.properties deleted file mode 100644 index e6356b6e141..00000000000 --- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/design.properties +++ /dev/null @@ -1,4 +0,0 @@ -org.sonar.plugins.design.ui.page.DesignPage.page=Design -org.sonar.plugins.design.ui.libraries.LibrariesPage.page=Libraries -org.sonar.plugins.design.ui.dependencies.DependenciesTab.page=Dependencies -org.sonar.plugins.design.ui.lcom4.Lcom4Tab.page=LCOM4 diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/gwt.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/gwt.properties new file mode 100644 index 00000000000..d36d51254e9 --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/gwt.properties @@ -0,0 +1,59 @@ +noData=No data +newWindow=New window + +# dependencies viewer (tab) +depsTab.afferentCouplings=Afferent (incoming) couplings +depsTab.efferentCouplings=Efferent (outgoing) couplings +depsTab.classes=Classes +depsTab.dit=Depth in Tree +depsTab.noc=Number of Children +depsTab.rfc=Response for Class +depsTab.lcom4=Lack of Cohesion of Methods + + +# Design page (DSM) +design.help=Help +design.legend.dependencies=Dependency +design.legend.cycles=Suspect dependency (cycle) +design.legend.uses=- uses > +design.cellTooltip=Click to highlight, double-click to display more details +design.rowTooltip=Click to highlight, double-click to zoom + + +# Libraries page +libs.filter=Filter: +libs.displayTests=Display test libraries +libs.expand=Expand all +libs.collapse=Collapse all +libs.noLibraries=No libraries +libs.usageLink=Usages + + +# Duplications viewer +dupl.lines=Lines +dupl.duplicated_lines=Duplicated lines +dupl.duplicated_blocks=Duplicated blocks +dupl.colSize=Nb lines +dupl.colFromLine=From line +dupl.colFile=File + + +# Hotspots +hotspot.mostViolatedRules=Most violated rules +hotspot.titleMostViolatedResources=Most violated +hotspot.titleLongestTests=Longest unit tests +hotspot.titleMostComplexResources=Highest complexity +hotspot.titleMostDuplicatedResources=Highest duplications +hotspot.titleLessTested=Highest untested lines +hotspot.titleMostComplexMethods=Highest average method complexity +hotspot.titleMostUndocumentedAPI=Most undocumented APIs +hotspot.noMeasures=No measures +hotspot.anySeverity=Any severity +hotspot.moreDetails=more +hotspot.lcom4=Lack of Cohesion of Methods +hotspot.rfc=Response for class +hotspot.designTitle=Highest + + +# LCOM4 viewer +lcom4.metric=Lack of Cohesion of Methods
\ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/GwtI18n.java b/sonar-core/src/main/java/org/sonar/core/i18n/GwtI18n.java new file mode 100644 index 00000000000..d3de526be98 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/i18n/GwtI18n.java @@ -0,0 +1,82 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.i18n; + +import com.google.common.collect.Lists; +import org.apache.commons.lang.StringEscapeUtils; +import org.sonar.api.ServerComponent; + +import java.util.*; + +public class GwtI18n implements ServerComponent { + public static final String GWT_BUNDLE = I18nManager.BUNDLE_PACKAGE + "gwt"; + + private I18nManager manager; + private String[] propertyKeys; + + public GwtI18n(I18nManager manager) { + this.manager = manager; + } + + public void start() { + doStart(getBundle(Locale.ENGLISH)); + } + + void doStart(ResourceBundle englishBundle) { + List<String> keys = Lists.newArrayList(); + Enumeration<String> enumeration = englishBundle.getKeys(); + while (enumeration.hasMoreElements()) { + String propertyKey = enumeration.nextElement(); + keys.add(propertyKey); + } + propertyKeys = keys.toArray(new String[keys.size()]); + } + + String[] getPropertyKeys() { + return propertyKeys; + } + + public String getJsDictionnary(Locale locale) { + ResourceBundle bundle = getBundle(locale); + return getJsDictionnary(bundle); + } + + String getJsDictionnary(ResourceBundle bundle) { + StringBuilder js = new StringBuilder("var l10n = {"); + for (int index = 0; index < propertyKeys.length; index++) { + String key = propertyKeys[index]; + String value = StringEscapeUtils.escapeJavaScript(bundle.getString(key)); + if (index > 0) { + js.append(","); + } + js.append("\"").append(key).append("\": \"").append(value).append("\""); + } + js.append("};"); + return js.toString(); + } + + ResourceBundle getBundle(Locale locale) { + try { + return ResourceBundle.getBundle(GWT_BUNDLE, locale, manager.getLanguagePackClassLoader()); + } catch (MissingResourceException e) { + throw new IllegalStateException("The English bundle for GWT extensions is not deployed", e); + } + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java index 65304cd44c0..9004a699a9f 100644 --- a/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java +++ b/sonar-core/src/main/java/org/sonar/core/i18n/I18nManager.java @@ -44,6 +44,7 @@ public class I18nManager implements I18n, ServerExtension { private PluginRepository pluginRepository; private Map<String, ClassLoader> bundleToClassloaders; private Map<String, String> propertyToBundles; + private ClassLoader languagePackClassLoader; public I18nManager(PluginRepository pluginRepository) { this.pluginRepository = pluginRepository; @@ -60,7 +61,7 @@ public class I18nManager implements I18n, ServerExtension { private void initClassloaders() { if (bundleToClassloaders == null) { - ClassLoader coreClassLoader = pluginRepository.getPlugin(ENGLISH_PACK_PLUGIN_KEY).getClass().getClassLoader(); + languagePackClassLoader = pluginRepository.getPlugin(ENGLISH_PACK_PLUGIN_KEY).getClass().getClassLoader(); bundleToClassloaders = Maps.newHashMap(); for (PluginMetadata metadata : pluginRepository.getMetadata()) { if (!metadata.isCore() && !ENGLISH_PACK_PLUGIN_KEY.equals(metadata.getBasePlugin())) { @@ -72,7 +73,7 @@ public class I18nManager implements I18n, ServerExtension { } else if (metadata.isCore()) { // bundles of core plugins are defined into language packs. All language packs are supposed // to share the same classloader (english pack classloader) - bundleToClassloaders.put(BUNDLE_PACKAGE + metadata.getKey(), coreClassLoader); + bundleToClassloaders.put(BUNDLE_PACKAGE + metadata.getKey(), languagePackClassLoader); } } } @@ -178,4 +179,8 @@ public class I18nManager implements I18n, ServerExtension { } return BUNDLE_PACKAGE + "core"; } + + ClassLoader getLanguagePackClassLoader() { + return languagePackClassLoader; + } } diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/GwtI18nTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/GwtI18nTest.java new file mode 100644 index 00000000000..bf45baf4869 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/i18n/GwtI18nTest.java @@ -0,0 +1,63 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.i18n; + +import com.google.common.collect.Lists; +import org.hamcrest.core.Is; +import org.junit.Before; +import org.junit.Test; + +import java.util.Locale; +import java.util.ResourceBundle; + +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; +import static org.junit.internal.matchers.StringContains.containsString; +import static org.junit.matchers.JUnitMatchers.hasItems; +import static org.mockito.Mockito.mock; + +public class GwtI18nTest { + + private GwtI18n i18n; + private ResourceBundle bundle; + + @Before + public void init() { + bundle = ResourceBundle.getBundle("org.sonar.core.i18n.GwtI18nTest.gwt", Locale.ENGLISH); + i18n = new GwtI18n(mock(I18nManager.class)); + i18n.doStart(bundle); + } + + @Test + public void shouldListAllPropertyKeysAtStartup() { + assertThat(i18n.getPropertyKeys().length, Is.is(2)); + assertThat(Lists.newArrayList(i18n.getPropertyKeys()), hasItems("one", "two")); + } + + @Test + public void shouldEncodeJavascriptValues() { + String js = i18n.getJsDictionnary(bundle); + assertThat(js, containsString("var l10n = {")); + assertThat(js, containsString("one\": \"One")); + assertThat(js, containsString("two\": \"Two")); + assertThat(js, containsString("};")); + assertThat(js, not(containsString(",};"))); // IE does not support empty key-values + } +} diff --git a/sonar-core/src/test/resources/org/sonar/core/i18n/GwtI18nTest/gwt.properties b/sonar-core/src/test/resources/org/sonar/core/i18n/GwtI18nTest/gwt.properties new file mode 100644 index 00000000000..da5fa91137a --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/i18n/GwtI18nTest/gwt.properties @@ -0,0 +1,2 @@ +one=One +two=Two
\ No newline at end of file diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 6835c7f69dd..2d8ef632fa9 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -41,6 +41,7 @@ import org.sonar.core.components.DefaultMetricFinder; import org.sonar.core.components.DefaultModelFinder; import org.sonar.core.components.DefaultRuleFinder; import org.sonar.core.components.DefaultUserFinder; +import org.sonar.core.i18n.GwtI18n; import org.sonar.core.i18n.I18nManager; import org.sonar.core.i18n.RuleI18nManager; import org.sonar.core.notifications.DefaultNotificationManager; @@ -191,6 +192,7 @@ public final class Platform { servicesContainer.as(Characteristics.CACHE).addComponent(DefaultUserFinder.class); servicesContainer.as(Characteristics.CACHE).addComponent(I18nManager.class); servicesContainer.as(Characteristics.CACHE).addComponent(RuleI18nManager.class); + servicesContainer.as(Characteristics.CACHE).addComponent(GwtI18n.class); // Notifications servicesContainer.as(Characteristics.CACHE).addComponent(NotificationService.class); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index df520e59ad2..e72305ebacd 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -338,6 +338,13 @@ public final class JRubyFacade { return i18n.searchRuleName(rubyLocale, searchText); } + public String getJsL10nDictionnary(String rubyLocale) { + if (i18n == null) { + i18n = getContainer().getComponent(JRubyI18n.class); + } + return i18n.getJsDictionnary(rubyLocale); + } + public ReviewsNotificationManager getReviewsNotificationManager() { return getContainer().getComponent(ReviewsNotificationManager.class); } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java index 077556d67b3..67ecb922744 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java @@ -20,14 +20,14 @@ package org.sonar.server.ui; import com.google.common.collect.Maps; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; import org.sonar.api.i18n.I18n; +import org.sonar.core.i18n.GwtI18n; import org.sonar.core.i18n.RuleI18nManager; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; /** * Bridge between JRuby webapp and Java I18n component @@ -37,10 +37,12 @@ public final class JRubyI18n implements ServerComponent { private I18n i18n; private Map<String, Locale> localesByRubyKey = Maps.newHashMap(); private RuleI18nManager ruleI18nManager; + private GwtI18n gwtI18n; - public JRubyI18n(I18n i18n, RuleI18nManager ruleI18nManager) { + public JRubyI18n(I18n i18n, RuleI18nManager ruleI18nManager, GwtI18n gwtI18n) { this.i18n = i18n; this.ruleI18nManager = ruleI18nManager; + this.gwtI18n = gwtI18n; } Locale getLocale(String rubyKey) { @@ -86,4 +88,8 @@ public final class JRubyI18n implements ServerComponent { public List<RuleI18nManager.RuleKey> searchRuleName(String rubyLocale, String searchText) { return ruleI18nManager.searchNames(searchText, toLocale(rubyLocale)); } + + public String getJsDictionnary(String rubyLocale) { + return gwtI18n.getJsDictionnary(toLocale(rubyLocale)); + } } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb index efb0a92af02..242ac153fae 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/gwt/_base.html.erb @@ -28,4 +28,5 @@ }; var modules = new Object(); + <%= Java::OrgSonarServerUi::JRubyFacade.getInstance().getJsL10nDictionnary(I18n.locale) -%> </script>
\ No newline at end of file diff --git a/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java b/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java index c03934a3940..7857d6d511d 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java @@ -22,6 +22,7 @@ package org.sonar.server.ui; import org.hamcrest.core.Is; import org.junit.Test; import org.sonar.api.i18n.I18n; +import org.sonar.core.i18n.GwtI18n; import org.sonar.core.i18n.RuleI18nManager; import java.util.Locale; @@ -40,7 +41,7 @@ public class JRubyI18nTest { @Test public void shouldCacheLocales() { - JRubyI18n i18n = new JRubyI18n(mock(I18n.class), mock(RuleI18nManager.class)); + JRubyI18n i18n = new JRubyI18n(mock(I18n.class), mock(RuleI18nManager.class), mock(GwtI18n.class)); assertThat(i18n.getLocalesByRubyKey().size(), Is.is(0)); i18n.getLocale("fr"); |