-
Notifications
You must be signed in to change notification settings - Fork 682
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
[#2064] Multilangual routes files support #1012
base: 1.4.x
Are you sure you want to change the base?
Conversation
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.
Some tests will be great too
framework/src/play/Play.java
Outdated
String virtualFileName = vf.getName(); | ||
if(virtualFileName !=null && virtualFileName.equals("routes")){ | ||
routes.add(vf); | ||
} else if(virtualFileName !=null && virtualFileName.matches("routes\\.[A-Za-z]{2}")){ |
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.
language can be defined on mode character to handle country specific code ex: en_US, en_UK
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.
@xael-fry So routes files can have also names like that routes.en_US ?
I will do tests.
Conflicts: framework/src/play/mvc/Router.java
Conflicts: framework/src/play/mvc/Router.java
I added tests, and changed some logic. Now you can add specific language routes file. For example routes.ru_RU, routes.fr_FR. |
Can please somebody review my pull request? |
@vadimv82 Could you stash your changes? |
framework/src/play/mvc/Router.java
Outdated
if(matchingRoutes.size()==0) return; | ||
final String locale = Lang.get(); | ||
if(StringUtils.isEmpty(locale)) return; | ||
matchingRoutes.sort(new Comparator<ActionRoute>() { |
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.
Jenkins cannot compile the code
[javac] matchingRoutes.sort(new Comparator<ActionRoute>() {
[javac] ^
[javac] symbol: method sort(<anonymous Comparator<ActionRoute>>)
[javac] location: variable matchingRoutes of type List<ActionRoute>
Seems like some method are missing as you use the interface Comparator
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 run same build on my machine with ant -buildfile ./framework/build.xml test
And build is succesfull.
I use anonymous comparator
sortedMatchingRoutes.sort(new Comparator() {
@OverRide
public int compare(ActionRoute ar1, ActionRoute ar2) {
if(locale.equals(ar1.route.locale)) return -1;
if(locale.equals(ar2.route.locale)) return 1;
return Integer.compare(Play.langs.indexOf(ar1.route.locale), Play.langs.indexOf(ar2.route.locale));
}
});
framework/src/play/Play.java
Outdated
@@ -114,7 +114,7 @@ public boolean isProd() { | |||
/** | |||
* Main routes file | |||
*/ | |||
public static VirtualFile routes; | |||
public static List<VirtualFile> routes; |
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 breaks backward compatibility.
I suggest leaving VirtualFile routes
untouched and adding a new field List<VirtualFile> internationalizedRoutes
. In this case you don't need field multilangRouteFiles
.
Multiple multilangual routes files support.
You can put several routes files into conf folder in a way:
routes.en, routes.fr, routes.ru.
Same route can have multiple urls for different languages.
Useful for SEO.