-
Notifications
You must be signed in to change notification settings - Fork 143
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
Conversation
Lhfcws
commented
Mar 2, 2017
- Add zh locale support
- Add simple url generator in NetworkProducer
- fix DateProducerSpec "should generate date between years #fromYear - #toYear", unpass test because the expect result is not correct
2. Add simple url generator in NetworkProducer
…#toYear" unpass because the expect result is not correct
Changes Unknown when pulling 5a630c2 on Lhfcws:master into ** on Codearte:master**. |
Related issue #78 |
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.
@Lhfcws Thank you very much for your contribution. It looks all right, but there are some changes that should be added. Please have a look at the comments.
@@ -115,7 +115,18 @@ public static Fairy create(Provider<DataMaster> dataMaster, Locale locale) { | |||
} | |||
|
|||
private static FairyModule getFairyModuleForLocale(DataMaster dataMaster, Locale locale, Random random) { | |||
LanguageCode code = LanguageCode.valueOf(locale.getLanguage().toUpperCase()); | |||
/** |
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.
I think the comment is unnecessary. You can add yourself in the file authors' list if you like.
+1 for the functionality.
@@ -67,8 +68,27 @@ private void generateDomain() { | |||
if (domain != null) { | |||
return; | |||
} | |||
domain = TextUtils.stripAccents(StringUtils.strip(StringUtils.deleteWhitespace(name.toLowerCase()), ".").replace("/", "")) | |||
+ "." + dataMaster.getRandomValue(DOMAIN); | |||
// domain = TextUtils.stripAccents(StringUtils.strip(StringUtils.deleteWhitespace(name.toLowerCase()), ".").replace("/", "")) |
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.
I think it would be actually better to switch CompanyProvider
to an interface and add the phonetic conversion. Would you like to provide the conversion mechanism? If you wouldn't like to work on it right now, we could go with a default mechanism. Please let me know. In any case, please remove the commented out code. If we are going to leave the default mechanism, I think it should be simplified, what about just verifying if it has non-latin characters and if yes, generating a random domain?
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.
I've considered the CompanyProvider problem. I just have no idea that changing your default mechanism is proper or not. And if CompanyProvider is changed to Interface, maybe the other providers like PersonProvider should also be changed to keep a uniform design.
I can work on it in 2 or 3 days.
And I think it is better to keep generating a fixed url for each different company if possible. Maybe some people generate pair of company and url relying on this mechanism, but it may not be a big deal.
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.
Maybe migration to Java 8 and a default method in that interface would be useful to reduce amount of changes in other providers?
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.
Yep, this feature is a little bit like Scala trait. It's convenient for code design. But I wonder if there may be a compatibility problem in different Java versions. There're some features in Java8 that cannot be supported in JRE-7, and I'm not sure if this one is included.
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.
It works only with Java 8. However, 2 years ago we started a discussion (#23) to drop support for Java 7 and it seems to be a good argument to do that.
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.
@OlgaMaciaszek @mariuszs Any objections?
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.
0.0 I've already commited Java7 Interface version.
return (char)(65 + r - 10); | ||
} | ||
|
||
private String getChars(int padding) { |
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.
It seems to be rather the number of chars to return than a padding. Consider renaming the parameter.
@@ -0,0 +1,70 @@ | |||
package io.codearte.jfairy.producer.person.locale.zh; |
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.
Could you extract the Chinese characters to constants?
/** | ||
* Total length of Chinese ID | ||
*/ | ||
private static final int ID_LENGTH = 15; |
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.
ID_LENGTH is never used. Can this be removed?
@@ -0,0 +1,105 @@ | |||
package io.codearte.jfairy.producer.company.locale.zh; |
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.
* Add a simple url generator | ||
* @return | ||
*/ | ||
public String url() { |
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.
I am not sure if it should be added here. Do you have a usecase for this? Maybe we could just add a method in the CompanyProvider that will use the domain field to generate urls just by prefixing it with https://?
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.
In some cases I need to generate random url for each user, and the original company urls is not enough. I assumed this is a very common demand and I couldn't find a generator in JFairy except company url. And as what I mentioned above, I believe that each company with a fixed url is better.
/** | ||
* Codes of China provinces | ||
*/ | ||
private static final String[] PROV_LIST = { |
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.
Is this the same list that is already used in ZhVATIdentificationNumberProvider
? If yes, please extract it somewhere and share between these classes.
/** | ||
* Codes of China provinces | ||
*/ | ||
private static final String[] PROV_LIST = { |
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.
/** | ||
* Total length of Chinese ID | ||
*/ | ||
private static final int ID_LENGTH = 18; |
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.
ID_LENGTH is never used. Can this be removed?
2. add https option to NetworkProducer.url(boolean isHttps) 3. move common shared constants of zh locale to ZhFairyUtil 4. move comments in Bootstrap.getFairyModuleForLocale to outside as a function's annotations
…ncrete class into DefaultXXProvider 7. FairyModule .configure add implement for guice install-build 8. Fix some test cases after the interface modification 9. Zh locale use ZhCompanyProvider independently
@OlgaMaciaszek I've made some modification according to your reviews, including switching the providers of Person/Company/IBAN into Interfaces. |
@Lhfcws thank you very much. I will review your new changes tomorrow. The reason we are hesitant when it comes to switching to Java 8 (although we do miss the features a lot, me at least) is that we have some Android users and it seems the support for Java 8 might not yet be stable. We will definitely make a switch once we see no problems for Android. |
Hi @OlgaMaciaszek . What's the progress of this PR now? |
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.
Thanks @Lhfcws . It looks really good now :). There just a few very minor changes to add and we will be able to merge. Please have a look at the comments.
@Override | ||
public void generateDomain() { | ||
if (domain != null) { | ||
return; |
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.
As this does not affect the latin languages, I think, it should be moved to CompanyProvider.java
as the default implementation. Like this, it will be possible to keep the original Company provider, call super.configure()
from ZhFairyModule
and keep the FairyModule
fields private.
|
||
private char getChar() { | ||
int rndNum = baseProducer.randomBetween(0, 35); | ||
if (rndNum < 10) |
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.
Plase add {}
to improve readability.
domainChars[i] = (char) (c + 97); | ||
} | ||
|
||
String domain = String.valueOf(domainChars); |
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 add {}
to improve readability.
*/ | ||
public class ZhFairyUtil { | ||
|
||
/** |
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.
You can add a private default constructor to make sure this class is only used to call static methods.
2. call super.configure() from ZhFairyModule and keep the FairyModule fields private.
Changes Unknown when pulling 291c793 on Lhfcws:master into ** on Codearte:master**. |
Got it. Done. |