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

I18n #47

Merged
merged 23 commits into from Sep 10, 2015
Merged

I18n #47

merged 23 commits into from Sep 10, 2015

Conversation

oberhamsi
Copy link
Member

This middleware gleans the locale based on various methods and puts it into the session.

ehoogerbeets and others added 20 commits July 4, 2015 01:03
Not tested yet. Still need to make sure it works before we attempt
to merge it anywhere.
If you give it a regular expression, there were various exceptions
which are now avoided.
Previously, if you passed a regular expression for the path, it
would give an exception.
This is not tested yet. Needs a little more work.
Most of the tests for the locale middleware are written and run
correctly without errors, but they do not all pass yet.
More tests pass now, but not all, and the code needs to be cleaned
a bit before this can become a PR.
* All unit tests pass, including the existing ones.
* Added build.properties in case ringo is not in your path and you want to define where it can be found
* Inline documentation is included in the lib/middleware/locale.js file
Converted all tabs to 4 spaces and removed spaces at the end of lines.
These are not related to the locale middleware, so they should
not be part of this PR.
Fixed whitespace issues, converting tabs to spaces, and removed
debug stuff.
Now catches exceptions and moves on without a locale.
In the session data, if you set an attribute to null or undefined,
and then read that variable again, it would return the string
"null" or "undefined" instead of the values null or undefined.
This fixes part of the problem. If you set the value of an attribute
to null or undefined, then it will unset the attribute as per the
HttpServlet 3.1 javadocs instead of setting it to a string. This
is still not quite working correctly, because if you unset a
variable and then test its value, it always returns null instead of
undefined.
In the session data, if you set an attribute to null or undefined,
and then read that variable again, it would return the string
"null" or "undefined" instead of the values null or undefined.
This fixes part of the problem. If you set the value of an attribute
to null or undefined, then it will unset the attribute as per the
HttpServlet 3.1 javadocs instead of setting it to a string. This
is still not quite working correctly, because if you unset a
variable and then test its value, it always returns null instead of
undefined.
@ehoogerbeets
Copy link
Contributor

@oberhamsi and @hns I think this PR is ready to be merged. I have been testing with it for a few weeks now while developing my own site, and it seems to be working fine for me.

@oberhamsi
Copy link
Member Author

@ehoogerbeets sorry about the delay - we've all been very busy the last weeks. I trust your tests but someone of the ringo core team will still have to look through it before merge.

@@ -79,7 +79,14 @@ var ServletSession = exports.ServletSession = function(request) {
// to the attributes in the servlet session object.
data = new JavaAdapter(org.mozilla.javascript.NativeObject, {
put: function(name, start, value) {
getSession().setAttribute(name, value);
if (typeof(value) === 'undefined' || value === null) {
Copy link
Member

Choose a reason for hiding this comment

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

This conforms to HttpSession's behavior:

If the value passed in is null, this has the same effect as calling removeAttribute().

http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpSession.html#setAttribute-java.lang.String-java.lang.Object-

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 drop it. same with the Object.prototype stuff below (which was already there)

@botic
Copy link
Member

botic commented Sep 8, 2015

I really like the middleware, but we should avoid manipulating the Object.prototype and just drop those lines.

Shouldn't be messing around with the Object prototype anyways!
Why does git make me do this? I hate git.
@ehoogerbeets
Copy link
Contributor

Thanks for looking at that Philipp! The code is removed now, and the stick tests still all pass as do the ones for my own web site. So it's ready to have another look.

@botic
Copy link
Member

botic commented Sep 9, 2015

@grob / @oberhamsi do you see any consequences from the addition of RegExp for routes? Otherwise I would merge this PR 👍

@botic botic self-assigned this Sep 9, 2015
spec.pattern = path instanceof RegExp ? path : normalizePath(path, keys);
spec.weight = calcWeight(path);
if (path instanceof RegExp) {
spec.pattern = path;
Copy link
Member

Choose a reason for hiding this comment

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

I think there is a tab instead of spaces. Minor thing, but cosmetics & consistency.

The regexp support will have to be rethought before they can be used.
];

var Locale = function Locale(spec) {
var bits = spec.split(/[-_]/g);
Copy link
Contributor

Choose a reason for hiding this comment

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

Later this class should be moved out to the utilities where it can be used more generally...

@ehoogerbeets
Copy link
Contributor

Okay, this PR should contain locale-only changes now.

@botic
Copy link
Member

botic commented Sep 9, 2015

A very clear merge it from my side 👍

botic added a commit that referenced this pull request Sep 10, 2015
New i18n middleware for stick.
@botic botic merged commit f8f0887 into ringo:master Sep 10, 2015
@oberhamsi
Copy link
Member Author

yey! thanks for your i18n efforts, @ehoogerbeets looking forward to using it myself :)

@ehoogerbeets
Copy link
Contributor

No probs... more to come on the reinhardt side of course.

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.

None yet

3 participants