From 4959f27a068900cda3c3b10d9042ec723bbe907f Mon Sep 17 00:00:00 2001 From: chebyshev Date: Wed, 15 Dec 2021 19:16:07 +0800 Subject: [PATCH 1/2] add new feature of i18n --- .../configuration/i18n/i18n_lib.properties | 18 +++++++++ .../packagenamingpackage/impl/Constants.java | 3 ++ .../impl/printers/BuzzStringPrinter.java | 4 +- .../impl/printers/FizzStringPrinter.java | 3 +- .../impl/printers/NewLineStringPrinter.java | 3 +- .../FizzBuzzOutputStrategyI18nProxy.java | 39 +++++++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 resources/assets/configuration/i18n/i18n_lib.properties create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java diff --git a/resources/assets/configuration/i18n/i18n_lib.properties b/resources/assets/configuration/i18n/i18n_lib.properties new file mode 100644 index 00000000..654e70d8 --- /dev/null +++ b/resources/assets/configuration/i18n/i18n_lib.properties @@ -0,0 +1,18 @@ +Fizz.Arabic=نفطة +Fizz.Brazilian=Fizz +Fizz.Chinese=嘶嘶 +Fizz.English=Fizz +Fizz.French=Cloques +Fizz.German=FizzGenericName +Fizz.Japanese=フィズ +Fizz.Korean=물집이 생기다 +Fizz.Italian=Fizz +Buzz.Arabic=أزيز +Buzz.Brazilian=Buzz +Buzz.Chinese=嗡嗡 +Buzz.English=Buzz +Buzz.French=Buzz +Buzz.German=Buzz +Buzz.Japanese=バズ +Buzz.Korean=윙윙거리는 소리 +Buzz.Italian=Bum diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java index f351e327..c65662cd 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java @@ -19,5 +19,8 @@ public class Constants { public static final int INTEGER_ORIGIN_ZERO_VALUE = 0; public static final int LOOP_INC_VALUE = 1; public static final int LOOP_INIT_VALUE = 1; + public static final String I18N_LIB_PROPERTIES_PATH = "assets/configuration/i18n/i18n_lib.properties"; + public static final String LANGUAGE = "Chinese"; + public static final String I18N_LIB_PROPERTIES_SEPARATOR = "."; } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java index 76de87a8..b2d61e0a 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,7 +40,8 @@ public void print() { .createStringStringReturner(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._outputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy( + this._outputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myBuzzStringReturner.getReturnString()); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java index 04cb8d14..340fe2a7 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,7 +40,7 @@ public void print() { .createStringStringReturner(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy(this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myFizzStringReturner.getReturnString()); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java index 8439ed5c..25489d14 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,7 +41,7 @@ public void print() { final String myNewLineString = myNewLineStringReturner.getReturnString(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy(this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myNewLineString); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java new file mode 100644 index 00000000..f274bb54 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java @@ -0,0 +1,39 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzOutputStrategy; +import org.springframework.core.io.support.PropertiesLoaderUtils; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * @author zwk + * @date 2021/12/15 + **/ +public class FizzBuzzOutputStrategyI18nProxy implements FizzBuzzOutputStrategy { + + private final FizzBuzzOutputStrategy _fizzBuzzOutputStrategy; + + public FizzBuzzOutputStrategyI18nProxy(final FizzBuzzOutputStrategy _fizzBuzzOutputStrategy) { + this._fizzBuzzOutputStrategy = _fizzBuzzOutputStrategy; + } + + /** + * @author zwk + * @date 17:53 2021/12/15 + * @param output + * @return void + **/ + @Override + public void output(String output) throws IOException { + Properties properties = PropertiesLoaderUtils.loadAllProperties(Constants.I18N_LIB_PROPERTIES_PATH); + String pathSuffix = Constants.I18N_LIB_PROPERTIES_SEPARATOR + Constants.LANGUAGE; + String fizz = properties.getProperty(Constants.FIZZ+pathSuffix); + String buzz = properties.getProperty(Constants.BUZZ+pathSuffix); + output = output.replaceAll(Constants.FIZZ,fizz).replaceAll(Constants.BUZZ,buzz); + this._fizzBuzzOutputStrategy.output(output); + } +} From 8b80993c7e8adaa0ef8437f20ebee3f88433ef34 Mon Sep 17 00:00:00 2001 From: chebyshev Date: Wed, 15 Dec 2021 19:16:07 +0800 Subject: [PATCH 2/2] add new feature of i18n --- .../configuration/i18n/i18n_lib.properties | 18 +++++++++ .../packagenamingpackage/impl/Constants.java | 3 ++ .../impl/printers/BuzzStringPrinter.java | 4 +- .../impl/printers/FizzStringPrinter.java | 3 +- .../impl/printers/NewLineStringPrinter.java | 3 +- .../FizzBuzzOutputStrategyI18nProxy.java | 39 +++++++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 resources/assets/configuration/i18n/i18n_lib.properties create mode 100644 src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java diff --git a/resources/assets/configuration/i18n/i18n_lib.properties b/resources/assets/configuration/i18n/i18n_lib.properties new file mode 100644 index 00000000..654e70d8 --- /dev/null +++ b/resources/assets/configuration/i18n/i18n_lib.properties @@ -0,0 +1,18 @@ +Fizz.Arabic=نفطة +Fizz.Brazilian=Fizz +Fizz.Chinese=嘶嘶 +Fizz.English=Fizz +Fizz.French=Cloques +Fizz.German=FizzGenericName +Fizz.Japanese=フィズ +Fizz.Korean=물집이 생기다 +Fizz.Italian=Fizz +Buzz.Arabic=أزيز +Buzz.Brazilian=Buzz +Buzz.Chinese=嗡嗡 +Buzz.English=Buzz +Buzz.French=Buzz +Buzz.German=Buzz +Buzz.Japanese=バズ +Buzz.Korean=윙윙거리는 소리 +Buzz.Italian=Bum diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java index f351e327..c310d9d4 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/Constants.java @@ -19,5 +19,8 @@ public class Constants { public static final int INTEGER_ORIGIN_ZERO_VALUE = 0; public static final int LOOP_INC_VALUE = 1; public static final int LOOP_INIT_VALUE = 1; + public static final String I18N_LIB_PROPERTIES_PATH = "assets/configuration/i18n/i18n_lib.properties"; + public static final String LANGUAGE = "French"; + public static final String I18N_LIB_PROPERTIES_SEPARATOR = "."; } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java index 76de87a8..b2d61e0a 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/BuzzStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,7 +40,8 @@ public void print() { .createStringStringReturner(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._outputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy( + this._outputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myBuzzStringReturner.getReturnString()); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java index 04cb8d14..340fe2a7 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/FizzStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -39,7 +40,7 @@ public void print() { .createStringStringReturner(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy(this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myFizzStringReturner.getReturnString()); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java index 8439ed5c..25489d14 100644 --- a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/printers/NewLineStringPrinter.java @@ -1,5 +1,6 @@ package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.printers; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies.FizzBuzzOutputStrategyI18nProxy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,7 +41,7 @@ public void print() { final String myNewLineString = myNewLineStringReturner.getReturnString(); final FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter myOutputAdapter = new FizzBuzzOutputStrategyToFizzBuzzExceptionSafeOutputStrategyAdapter( - this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy()); + new FizzBuzzOutputStrategyI18nProxy(this._systemOutFizzBuzzOutputStrategyFactory.createOutputStrategy())); myOutputAdapter.output(myNewLineString); } diff --git a/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java new file mode 100644 index 00000000..f274bb54 --- /dev/null +++ b/src/main/java/com/seriouscompany/business/java/fizzbuzz/packagenamingpackage/impl/strategies/FizzBuzzOutputStrategyI18nProxy.java @@ -0,0 +1,39 @@ +package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.strategies; + +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl.Constants; +import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzOutputStrategy; +import org.springframework.core.io.support.PropertiesLoaderUtils; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * @author zwk + * @date 2021/12/15 + **/ +public class FizzBuzzOutputStrategyI18nProxy implements FizzBuzzOutputStrategy { + + private final FizzBuzzOutputStrategy _fizzBuzzOutputStrategy; + + public FizzBuzzOutputStrategyI18nProxy(final FizzBuzzOutputStrategy _fizzBuzzOutputStrategy) { + this._fizzBuzzOutputStrategy = _fizzBuzzOutputStrategy; + } + + /** + * @author zwk + * @date 17:53 2021/12/15 + * @param output + * @return void + **/ + @Override + public void output(String output) throws IOException { + Properties properties = PropertiesLoaderUtils.loadAllProperties(Constants.I18N_LIB_PROPERTIES_PATH); + String pathSuffix = Constants.I18N_LIB_PROPERTIES_SEPARATOR + Constants.LANGUAGE; + String fizz = properties.getProperty(Constants.FIZZ+pathSuffix); + String buzz = properties.getProperty(Constants.BUZZ+pathSuffix); + output = output.replaceAll(Constants.FIZZ,fizz).replaceAll(Constants.BUZZ,buzz); + this._fizzBuzzOutputStrategy.output(output); + } +}