Title: [1286] trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n: JBEHAVE-164: Removed i18n keyword bundles from core, apart from default en locale.
Revision
1286
Author
mauro
Date
2009-10-04 06:28:53 -0500 (Sun, 04 Oct 2009)

Log Message

JBEHAVE-164:  Removed i18n keyword bundles from core, apart from default en locale.  Bundles should be provided separately and encoding issues should be addressed.
Updated behaviour and example to use different configurable locale and bundle.  

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderScenario.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -6,6 +6,7 @@
 import org.jbehave.scenario.PropertyBasedConfiguration;
 import org.jbehave.scenario.definition.KeyWords;
 import org.jbehave.scenario.i18n.I18nKeyWords;
+import org.jbehave.scenario.i18n.StringEncoder;
 import org.jbehave.scenario.parser.ClasspathScenarioDefiner;
 import org.jbehave.scenario.parser.PatternScenarioParser;
 import org.jbehave.scenario.parser.ScenarioDefiner;
@@ -32,16 +33,20 @@
 			@Override
 			public ScenarioReporter forReportingScenarios() {
 				// report outcome in Italian (to System.out)
-				return new PrintStreamScenarioReporter(new I18nKeyWords(new Locale("it")));
+				return new PrintStreamScenarioReporter(keywordsFor(new Locale("it"), classLoader));
 			}
 
 			@Override
 			public KeyWords keywords() {
 				// use Italian for keywords
-				return new I18nKeyWords(new Locale("it"));
+				return keywordsFor(new Locale("it"), classLoader);
 			}
 
 		}, new ItTraderSteps(classLoader));
 	}
 
+	protected static KeyWords keywordsFor(Locale locale, ClassLoader classLoader) {
+		return new I18nKeyWords(locale, new StringEncoder(), "org/jbehave/examples/trader/i18n/keywords", classLoader);
+	}
+
 }

Modified: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/ItTraderSteps.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -10,7 +10,9 @@
 import org.jbehave.scenario.annotations.Named;
 import org.jbehave.scenario.annotations.Then;
 import org.jbehave.scenario.annotations.When;
+import org.jbehave.scenario.definition.KeyWords;
 import org.jbehave.scenario.i18n.I18nKeyWords;
+import org.jbehave.scenario.i18n.StringEncoder;
 import org.jbehave.scenario.steps.Steps;
 import org.jbehave.scenario.steps.StepsConfiguration;
 
@@ -20,7 +22,7 @@
 
     public ItTraderSteps(ClassLoader classLoader) {
     	// Use Italian for keywords
-        super(new StepsConfiguration(new I18nKeyWords(new Locale("it"))));
+        super(new StepsConfiguration(keywordsFor(new Locale("it"), classLoader)));
     }
 
     @Given("ho un'azione con simbolo $symbol e una soglia di $threshold")
@@ -38,4 +40,8 @@
         ensureThat(stock.getStatus().name(), equalTo(status));
     }
 
+	protected static KeyWords keywordsFor(Locale locale, ClassLoader classLoader) {
+		return new I18nKeyWords(locale, new StringEncoder(), "org/jbehave/examples/trader/i18n/keywords", classLoader);
+	}
+
 }

Deleted: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderScenario.java (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderScenario.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderScenario.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,49 +0,0 @@
-package org.jbehave.examples.trader.i18n;
-
-import java.util.Locale;
-
-import org.jbehave.scenario.JUnitScenario;
-import org.jbehave.scenario.PropertyBasedConfiguration;
-import org.jbehave.scenario.definition.KeyWords;
-import org.jbehave.scenario.i18n.I18nKeyWords;
-import org.jbehave.scenario.parser.ClasspathScenarioDefiner;
-import org.jbehave.scenario.parser.PatternScenarioParser;
-import org.jbehave.scenario.parser.ScenarioDefiner;
-import org.jbehave.scenario.parser.UnderscoredCamelCaseResolver;
-import org.jbehave.scenario.reporters.PrintStreamScenarioReporter;
-import org.jbehave.scenario.reporters.ScenarioReporter;
-
-public class PtTraderScenario extends JUnitScenario {
-
-	public PtTraderScenario() {
-		this(Thread.currentThread().getContextClassLoader());
-	}
-
-	public PtTraderScenario(final ClassLoader classLoader) {
-		super(new PropertyBasedConfiguration() {
-			@Override
-			public ScenarioDefiner forDefiningScenarios() {
-				// use underscored camel case scenario files with extension
-				// ".cenario"
-				return new ClasspathScenarioDefiner(
-						new UnderscoredCamelCaseResolver(".cenario"),
-						new PatternScenarioParser(this), classLoader);
-			}
-
-			@Override
-			public ScenarioReporter forReportingScenarios() {
-				// report outcome in Portuguese (to System.out)
-				return new PrintStreamScenarioReporter(new I18nKeyWords(
-						new Locale("pt")));
-			}
-
-			@Override
-			public KeyWords keywords() {
-				// use Portuguese for keywords
-				return new I18nKeyWords(new Locale("pt"));
-			}
-
-		}, new PtTraderSteps(classLoader));
-	}
-
-}

Deleted: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderSteps.java (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderSteps.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/PtTraderSteps.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,42 +0,0 @@
-package org.jbehave.examples.trader.i18n;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.jbehave.Ensure.ensureThat;
-
-import java.util.Locale;
-
-import org.jbehave.examples.trader.model.Stock;
-import org.jbehave.scenario.annotations.Given;
-import org.jbehave.scenario.annotations.Named;
-import org.jbehave.scenario.annotations.Then;
-import org.jbehave.scenario.annotations.When;
-import org.jbehave.scenario.i18n.I18nKeyWords;
-import org.jbehave.scenario.steps.Steps;
-import org.jbehave.scenario.steps.StepsConfiguration;
-
-public class PtTraderSteps extends Steps {
-
-	private Stock stock;
-
-	public PtTraderSteps(ClassLoader classLoader) {
-		// Use Portuguese for keywords
-		super(new StepsConfiguration(new I18nKeyWords(new Locale("pt"))));
-	}
-
-	@Given("ha uma acao com simbolo $symbol e um limite de $threshold")
-	public void aStock(@Named("symbol") String symbol,
-			@Named("threshold") double threshold) {
-		stock = new Stock(symbol, threshold);
-	}
-
-	@When("a acao e' oferecida ao preco de $price")
-	public void stockIsTraded(@Named("price") double price) {
-		stock.tradeAt(price);
-	}
-
-	@Then("o estado de alerta e' $status")
-	public void alertStatusIs(@Named("status") String status) {
-		ensureThat(stock.getStatus().name(), equalTo(status));
-	}
-
-}

Copied: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties (from rev 1278, trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_it.properties) (0 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	                        (rev 0)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/keywords_it.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -0,0 +1,11 @@
+Scenario=Scenario:
+GivenScenarios=Dati gli scenari:
+ExamplesTable=Esempi:
+ExamplesTableRow=Esempio:
+Given=Dato che
+When=Quando
+Then=Allora
+And=E
+Pending=PENDENTE
+NotPerformed=NON ESEGUITO
+Failed=FALLITO

Deleted: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/PtTraderIsAlertedOfStatus.java (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/PtTraderIsAlertedOfStatus.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/PtTraderIsAlertedOfStatus.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,16 +0,0 @@
-package org.jbehave.examples.trader.i18n.scenarios;
-
-import org.jbehave.examples.trader.i18n.PtTraderScenario;
-
-
-public class PtTraderIsAlertedOfStatus extends PtTraderScenario {
-
-    public PtTraderIsAlertedOfStatus() {
-        this(Thread.currentThread().getContextClassLoader());
-    }
-
-    public PtTraderIsAlertedOfStatus(final ClassLoader classLoader) {
-    	super(classLoader);
-    }
-
-}

Deleted: trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/pt_trader_is_alerted_of_status.cenario (1285 => 1286)

--- trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/pt_trader_is_alerted_of_status.cenario	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/examples/trader/src/main/java/org/jbehave/examples/trader/i18n/scenarios/pt_trader_is_alerted_of_status.cenario	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,14 +0,0 @@
-Cenario:
-Para assegurar uma resposta rápida
-Como um negociante que fala português
-Quero monitorar os preços das ações
-
-Dado que ha uma acao com simbolo STK1 e um limite de 15.0
-Quando a acao e' oferecida ao preco de 5.0
-Entao o estado de alerta e' OFF
-Quando a acao e' oferecida ao preco de 11.0
-Entao o estado de alerta e' OFF
-Quando a acao e' oferecida ao preco de 16.0
-Entao o estado de alerta e' ON
-Quando a acao e' oferecida ao precooooooo de 20.0
-Entao o estado de alerta e' ON

Modified: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java (1285 => 1286)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/I18nKeywordsBehaviour.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -12,35 +12,21 @@
 public class I18nKeywordsBehaviour {
 
 	private StringEncoder encoder = new StringEncoder("UTF-8", "UTF-8");
-	
+
 	@Test
 	public void keywordsInEnglishAsDefault() throws IOException {
 		ensureKeywordsAreLocalisedFor(null);
 	}
 
 	@Test
-	public void keywordsInSpanish() throws IOException {
-		ensureKeywordsAreLocalisedFor(new Locale("es"));
-	}
-
-	@Test
-	public void keywordsInFrench() throws IOException {
-		ensureKeywordsAreLocalisedFor(new Locale("fr"));
-	}
-	
-    @Test
 	public void keywordsInItalian() throws IOException {
 		ensureKeywordsAreLocalisedFor(new Locale("it"));
 	}
 
-	@Test
-	public void keywordsInPortuguese() throws IOException {
-		ensureKeywordsAreLocalisedFor(new Locale("pt"));
-	}
-
-	private void ensureKeywordsAreLocalisedFor(Locale locale) throws IOException {
+	private void ensureKeywordsAreLocalisedFor(Locale locale)
+			throws IOException {
 		Properties properties = bundleFor(locale);
-		KeyWords keywords = keyWordsFor(locale);		
+		KeyWords keywords = keyWordsFor(locale);
 		ensureKeywordIs(properties, "Scenario", keywords.scenario());
 		ensureKeywordIs(properties, "GivenScenarios", keywords.givenScenarios());
 		ensureKeywordIs(properties, "ExamplesTable", keywords.examplesTable());
@@ -55,14 +41,16 @@
 	}
 
 	private I18nKeyWords keyWordsFor(Locale locale) {
-		return (locale == null ? new I18nKeyWords()
-				: new I18nKeyWords(locale));
+		return (locale == null ? new I18nKeyWords() : new I18nKeyWords(locale));
 	}
 
 	private Properties bundleFor(Locale locale) throws IOException {
 		Properties expected = new Properties();
-		String bundle = "org/jbehave/scenario/i18n/keywords_"+( locale == null ? "en" : locale.getLanguage()) +".properties";
-		expected.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(bundle));
+		String bundle = "org/jbehave/scenario/i18n/keywords_"
+				+ (locale == null ? "en" : locale.getLanguage())
+				+ ".properties";
+		expected.load(Thread.currentThread().getContextClassLoader()
+				.getResourceAsStream(bundle));
 		return expected;
 	}
 

Copied: trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/keywords_it.properties (from rev 1278, trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_it.properties) (0 => 1286)

--- trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/keywords_it.properties	                        (rev 0)
+++ trunk/core/jbehave-core/src/behaviour/org/jbehave/scenario/i18n/keywords_it.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -0,0 +1,11 @@
+Scenario=Scenario:
+GivenScenarios=Dati gli scenari:
+ExamplesTable=Esempi:
+ExamplesTableRow=Esempio:
+Given=Dato che
+When=Quando
+Then=Allora
+And=E
+Pending=PENDENTE
+NotPerformed=NON ESEGUITO
+Failed=FALLITO

Deleted: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/EmptyResourceBundle.java (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/EmptyResourceBundle.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/EmptyResourceBundle.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) terms as published in http://waffle.codehaus.org/license.html
- */
-package org.jbehave.scenario.i18n;
-
-import java.util.ListResourceBundle;
-
-/**
- * Empty resource bundle, used as <a
- * href="" when
- * no resource bundle is found.
- * 
- * @author Mauro Talevi
- */
-class EmptyResourceBundle extends ListResourceBundle {
-    @Override
-    protected Object[][] getContents() {
-        return new Object[][] { { "", "" } };
-    }
-}

Modified: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/I18nKeyWords.java (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/I18nKeyWords.java	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/I18nKeyWords.java	2009-10-04 11:28:53 UTC (rev 1286)
@@ -10,28 +10,27 @@
 
 public class I18nKeyWords extends KeyWords {
 
-	private static final ResourceBundle EMPTY_BUNDLE = new EmptyResourceBundle();
 	private static final String DEFAULT_BUNDLE_NAME = "org/jbehave/scenario/i18n/keywords";
 
 	public I18nKeyWords() {
-        this(DEFAULT_BUNDLE_NAME, Locale.ENGLISH, new StringEncoder());
+        this(Locale.ENGLISH, new StringEncoder(), DEFAULT_BUNDLE_NAME,  Thread.currentThread().getContextClassLoader());
     }
 
     public I18nKeyWords(Locale locale) {
-    	this(DEFAULT_BUNDLE_NAME, locale,  new StringEncoder());
+    	this(locale, new StringEncoder(),  DEFAULT_BUNDLE_NAME, Thread.currentThread().getContextClassLoader());
     }
 
     public I18nKeyWords(Locale locale,  StringEncoder encoder) {
-    	this(DEFAULT_BUNDLE_NAME, locale, encoder);
+    	this(locale, encoder, DEFAULT_BUNDLE_NAME, Thread.currentThread().getContextClassLoader());
     }
 
-    public I18nKeyWords(String bundleName, Locale locale, StringEncoder encoder) {
-    	super(keywords(bundleName, locale, encoder), encoder);
+    public I18nKeyWords(Locale locale, StringEncoder encoder, String bundleName, ClassLoader classLoader) {
+    	super(keywords(bundleName, locale, encoder, classLoader), encoder);
     }
 
 	private static Map<String, String> keywords(String bundleName,
-			Locale locale, StringEncoder encoder) {
-		ResourceBundle bundle = lookupBunde(bundleName, locale);
+			Locale locale, StringEncoder encoder, ClassLoader classLoader) {
+		ResourceBundle bundle = lookupBunde(bundleName, locale, classLoader);
 		Map<String, String> keywords = new HashMap<String, String>();
 		for ( String key : KEYWORDS ) {
 			keywords.put(key, keyword(bundle, key, encoder));			
@@ -43,12 +42,22 @@
 		return encoder.encode(bundle.getString(name));
 	}
 
-    private static ResourceBundle lookupBunde(String bundleName, Locale locale) {
+    private static ResourceBundle lookupBunde(String bundleName, Locale locale, ClassLoader classLoader) {
         try {
-            return ResourceBundle.getBundle(bundleName.trim(), locale);
+            return ResourceBundle.getBundle(bundleName.trim(), locale, classLoader);
         } catch (MissingResourceException e) {
-            return EMPTY_BUNDLE;
+            throw new ResourceBundleNotFoundExcepion(bundleName, locale, classLoader, e);
         }
     }
+    
+	@SuppressWarnings("serial")
+	public static final class ResourceBundleNotFoundExcepion extends RuntimeException {
 
+		public ResourceBundleNotFoundExcepion(String bundleName,
+				Locale locale, ClassLoader classLoader, MissingResourceException cause) {
+			super("Resource bundle "+bundleName+" not found for locale "+locale+" in classLoader "+classLoader, cause);
+		}
+
+	}
+
 }

Deleted: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_es.properties (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_es.properties	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_es.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,11 +0,0 @@
-Scenario=Escenario:
-GivenScenarios=Dados los escenarios:
-ExamplesTable=Ejemplos:
-ExamplesTableRow=Ejemplo:
-Given=Dado que
-When=Cuando
-Then=Entonces
-And=Y
-Pending=PENDIENTE
-NotPerformed=NO REALIZADO
-Failed=FRACASADO

Deleted: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_fr.properties (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_fr.properties	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_fr.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,11 +0,0 @@
-Scenario=Scenario:
-GivenScenarios=Donne les scenarios:
-ExamplesTable=Exemples:
-ExamplesTableRow=Exemple:
-Given=Etant donne
-When=Quand
-Then=Alors
-And=Et
-Pending=EN ATTENDANT
-NotPerformed=NON EXECUTE
-Failed=ECHOUE

Deleted: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_it.properties (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_it.properties	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_it.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,11 +0,0 @@
-Scenario=Scenario:
-GivenScenarios=Dati gli scenari:
-ExamplesTable=Esempi:
-ExamplesTableRow=Esempio:
-Given=Dato che
-When=Quando
-Then=Allora
-And=E
-Pending=PENDENTE
-NotPerformed=NON ESEGUITO
-Failed=FALLITO

Deleted: trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_pt.properties (1285 => 1286)

--- trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_pt.properties	2009-10-03 08:32:26 UTC (rev 1285)
+++ trunk/core/jbehave-core/src/java/org/jbehave/scenario/i18n/keywords_pt.properties	2009-10-04 11:28:53 UTC (rev 1286)
@@ -1,11 +0,0 @@
-Scenario=Cenario:
-GivenScenarios=Dados os cenarios:
-ExamplesTable=Exemplos:
-ExamplesTableRow=Exemplo:
-Given=Dado que
-When=Quando
-Then=Entao
-And=E
-Pending=PENDENTE
-NotPerformed=NAO EXECUTADO
-Failed=FALHADO


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to