-
Notifications
You must be signed in to change notification settings - Fork 142
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
Chinese Locale Support #80
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a553c55
1. Add zh locale support
5a630c2
fix DateProducerSpec "should generate date between years #fromYear - …
4bfadf2
1. fix some parameter names issue
c95dcb0
5. add more chinese words in jfairy-zh.yml text field
e0e50d0
6. make Company/Person/IBAN provider into Interface and change the co…
5926e0f
10. make ZhAddress Chinese characters into constants
65243b8
add brackets {} to improve readability.
7a953b2
1. move non-latin generateDomain() back to default CompanyProvider
291c793
complete some documents
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.codearte.jfairy; | ||
|
||
import io.codearte.jfairy.data.DataMaster; | ||
import io.codearte.jfairy.producer.VATIdentificationNumberProvider; | ||
import io.codearte.jfairy.producer.company.locale.zh.ZhVATIdentificationNumberProvider; | ||
import io.codearte.jfairy.producer.person.*; | ||
import io.codearte.jfairy.producer.person.locale.NoNationalIdentificationNumberFactory; | ||
import io.codearte.jfairy.producer.person.locale.zh.ZhAddressProvider; | ||
import io.codearte.jfairy.producer.person.locale.zh.ZhNationalIdentityCardNumberProvider; | ||
import io.codearte.jfairy.producer.person.locale.zh.ZhPassportNumberProvider; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* io.codearte.jfairy.ZhFairyModule | ||
* | ||
* @author lhfcws | ||
* @since 2017/03/01 | ||
*/ | ||
public class ZhFairyModule extends FairyModule { | ||
public ZhFairyModule(DataMaster dataMaster, Random random) { | ||
super(dataMaster, random); | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
super.configure(); | ||
|
||
// Social Insurance Number is the same as ID number in China now | ||
bind(NationalIdentificationNumberFactory.class).to(NoNationalIdentificationNumberFactory.class); | ||
bind(NationalIdentityCardNumberProvider.class).to(ZhNationalIdentityCardNumberProvider.class); | ||
bind(VATIdentificationNumberProvider.class).to(ZhVATIdentificationNumberProvider.class); | ||
bind(AddressProvider.class).to(ZhAddressProvider.class); | ||
bind(PassportNumberProvider.class).to(ZhPassportNumberProvider.class); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/io/codearte/jfairy/producer/company/CompanyProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/io/codearte/jfairy/producer/company/DefaultCompanyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package io.codearte.jfairy.producer.company; | ||
|
||
import com.google.inject.assistedinject.Assisted; | ||
import io.codearte.jfairy.data.DataMaster; | ||
import io.codearte.jfairy.producer.BaseProducer; | ||
import io.codearte.jfairy.producer.VATIdentificationNumberProvider; | ||
import io.codearte.jfairy.producer.util.TextUtils; | ||
import org.apache.commons.lang3.StringEscapeUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class DefaultCompanyProvider implements CompanyProvider { | ||
|
||
protected String name; | ||
protected String domain; | ||
protected String email; | ||
protected String vatIdentificationNumber; | ||
|
||
protected BaseProducer baseProducer; | ||
protected DataMaster dataMaster; | ||
|
||
protected VATIdentificationNumberProvider vatIdentificationNumberProvider; | ||
|
||
@Inject | ||
public DefaultCompanyProvider(BaseProducer baseProducer, | ||
DataMaster dataMaster, | ||
VATIdentificationNumberProvider vatIdentificationNumberProvider, | ||
@Assisted CompanyProperties.CompanyProperty... companyProperties) { | ||
this.baseProducer = baseProducer; | ||
this.dataMaster = dataMaster; | ||
this.vatIdentificationNumberProvider = vatIdentificationNumberProvider; | ||
|
||
for (CompanyProperties.CompanyProperty companyProperty : companyProperties) { | ||
companyProperty.apply(this); | ||
} | ||
} | ||
|
||
@Override | ||
public Company get() { | ||
|
||
generateName(); | ||
generateDomain(); | ||
generateEmail(); | ||
generateVatIdentificationNumber(); | ||
|
||
return new Company(name, domain, email, vatIdentificationNumber); | ||
} | ||
|
||
@Override | ||
public void generateName() { | ||
if (name != null) { | ||
return; | ||
} | ||
name = dataMaster.getRandomValue(COMPANY_NAME); | ||
if (baseProducer.trueOrFalse()) { | ||
name += " " + dataMaster.getRandomValue(COMPANY_SUFFIX); | ||
} | ||
} | ||
|
||
/** | ||
* In case of the illegal hostname characters in company name | ||
* and truncate it if it is too long (length > 10) after escape | ||
* | ||
* It is compatible with other non-latin language and will not change the original result for latin language. | ||
* | ||
* P.S. Actually the best way for Chinese here is to use phonetic writing (so as Japanese or Korean) | ||
*/ | ||
@Override | ||
public void generateDomain() { | ||
if (domain != null) { | ||
return; | ||
} | ||
|
||
String host = TextUtils.stripAccents(StringUtils.strip(StringUtils.deleteWhitespace(name.toLowerCase()), ".").replace("/", "")); | ||
int len1 = host.length(); | ||
host = StringEscapeUtils.escapeJava(host).replaceAll("\\\\u", ""); | ||
int len2 = host.length(); | ||
if (len2 > len1 && len2 > 10) | ||
host = host.substring(0, 10); | ||
|
||
domain = host + "." + dataMaster.getRandomValue(DOMAIN); | ||
} | ||
|
||
@Override | ||
public void generateEmail() { | ||
if (email != null) { | ||
return; | ||
} | ||
email = dataMaster.getRandomValue(COMPANY_EMAIL); | ||
} | ||
|
||
@Override | ||
public void generateVatIdentificationNumber() { | ||
if (vatIdentificationNumber != null) { | ||
return; | ||
} | ||
vatIdentificationNumber = vatIdentificationNumberProvider.get(); | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void setDomain(String domain) { | ||
this.domain = domain; | ||
} | ||
|
||
@Override | ||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
@Override | ||
public void setVatIdentificationNumber(String vatIdentificationNumber) { | ||
this.vatIdentificationNumber = vatIdentificationNumber; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...java/io/codearte/jfairy/producer/company/locale/zh/ZhVATIdentificationNumberProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.codearte.jfairy.producer.company.locale.zh; | ||
|
||
import io.codearte.jfairy.producer.BaseProducer; | ||
import io.codearte.jfairy.producer.VATIdentificationNumberProvider; | ||
|
||
import java.util.Random; | ||
|
||
import static io.codearte.jfairy.producer.util.ZhFairyUtil.*; | ||
|
||
/** | ||
* io.codearte.jfairy.producer.company.locale.zh.ZhVATIdentificationNumberProvider | ||
* | ||
* 6 digit for area location, 9 char (0-9A-Z) for organization code (2 char for business type, 2 char for industry type, 5 char for order number), total 15 digit | ||
* | ||
* @author lhfcws | ||
* @since 2017/3/1 | ||
*/ | ||
public class ZhVATIdentificationNumberProvider implements VATIdentificationNumberProvider { | ||
|
||
private static BaseProducer baseProducer = new BaseProducer(new Random()); | ||
|
||
@Override | ||
public String get() { | ||
StringBuilder vatBuilder = new StringBuilder(); | ||
vatBuilder.append(baseProducer.randomElement(PROV_LIST)); | ||
vatBuilder.append(getRandomNumStr(baseProducer, CITY_MAX, 2)); | ||
vatBuilder.append(getRandomNumStr(baseProducer, DISTRICT_MAX, 2)); | ||
vatBuilder.append(getChars(9)); | ||
return vatBuilder.toString(); | ||
} | ||
|
||
private char getChar() { | ||
int rndNum = baseProducer.randomBetween(0, 35); | ||
if (rndNum < 10) { | ||
return (char) (49 + rndNum); | ||
} else { | ||
return (char) (65 + rndNum - 10); | ||
} | ||
} | ||
|
||
private String getChars(int paddingSize) { | ||
StringBuilder sb = new StringBuilder(); | ||
for (int i = 0; i < paddingSize; i++) { | ||
sb.append(getChar()); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change your local variables such as
s
,r
, etc., to have more miningful names.