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

Adding Locale object as parameter to DeliveryParameterBuilder #30

Merged
merged 2 commits into from
Sep 28, 2017
Merged

Adding Locale object as parameter to DeliveryParameterBuilder #30

merged 2 commits into from
Sep 28, 2017

Conversation

cunhazera
Copy link
Contributor

Solve this: #28

@cunhazera
Copy link
Contributor Author

@aweigold I getting an error with the build on travis. Do you know what it is?

Copy link
Contributor

@aweigold aweigold left a comment

Choose a reason for hiding this comment

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

Confirm if the Kentico API will accept a language with an underscore between the language and variant instead of a hyphen, if it does not, this method will need to do that String manipulation as toString() on a Locale formats it with an underscore.

@@ -179,6 +180,13 @@ public DeliveryParameterBuilder language(String language) {
return this;
}

public DeliveryParameterBuilder language(Locale language) {
if (language != null) {
nameValuePairs.add(new BasicNameValuePair(LANGUAGE, language.toString()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This might not work. Although you can manually make a locale in the "-" syntax, you are actually only setting the language doing so. Constructing language with a variant with a Java locale is done via one of the following examples:

Locale.UK
new Locale("en", "GB")

The toString() method on Locale will return a locale formatted as "_", which doesn't match the spec from the Kentico API. Unless that format is supported, this method will need to do the proper string formatting.

Copy link
Contributor Author

@cunhazera cunhazera Sep 28, 2017

Choose a reason for hiding this comment

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

@aweigold so new Locale("en", "GB") must return en-GB ?
If this is the case, I can replace the "_" for "-"

Copy link
Contributor

Choose a reason for hiding this comment

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

That can work. You will also want to unit test an edge case where no variant is set, so if just new Locale("en") is passed, you are not sending in "en-".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aweigold if the client passes only new Locale("en") is must return only "en"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it's working correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

@cunhazera "So it's working correctly" as in the Kentico API will accept the underscores? Or it's working correctly if you just replace the "_" for "-" ? If the latter, that replacement will work, I was just advising that it would make sense to do a unit test for that case as well.

@@ -272,8 +272,17 @@ public void testLanguage() {
}

@Test
public void testLocaleLanguage() {
List<NameValuePair> params = DeliveryParameterBuilder.params().language(new Locale("pt-br")).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is only setting the language "pt-br" instead of the language "pt" with variant "br".

@aweigold
Copy link
Contributor

The PR build issue is fixed with #31

@@ -182,7 +182,7 @@ public DeliveryParameterBuilder language(String language) {

public DeliveryParameterBuilder language(Locale language) {
if (language != null) {
nameValuePairs.add(new BasicNameValuePair(LANGUAGE, language.toString()));
nameValuePairs.add(new BasicNameValuePair(LANGUAGE, language.toString().replace('_', '-')));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@aweigold
Copy link
Contributor

Looks like I spoke too soon on the PR fix... this is good to merge in. Thanks!

@aweigold aweigold merged commit 90e39fd into kontent-ai:master Sep 28, 2017
@cunhazera
Copy link
Contributor Author

@aweigold thank you, man.

@petrsvihlik
Copy link
Contributor

thank you @cunhazera and @aweigold !

@petrsvihlik
Copy link
Contributor

Hi @cunhazera,
we would like to send you some Kentico Cloud stickers as a thanks for taking part in Hacktoberfest. If you want them, please send us your postal address at developerscommunity@kentico.com.

@cunhazera
Copy link
Contributor Author

Hello @petrsvihlik I just sent an email with my address. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants