Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added i18n #549

Open
wants to merge 3 commits into
base: uinverse
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions resources/assets/configuration/i18n/i18n_lib.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Fizz.Arabic=نفطة
Fizz.Brazilian=Fizz
Fizz.Chinese=嘶嘶
Fizz.English=Fizz
Fizz.French=Cloques
Fizz.German=FizzGenericName
Copy link

@PurHur PurHur Jun 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no translation for eigennamen in german. The FizzBuzz application is called fizz buzz in german so you could simple use Fizz here.

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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ".";

}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Spring documentation, this method always uses ISO-8859-1, for compatibility with the 1990s. Did you verify that this code works properly on Microsoft Windows, printing the intended messages instead of mojibake?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good idea. Many of our users are in 1995, thought the majority of our users are in 2007.

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);
}
}