[#2064] Multilangual routes files support#1012
[#2064] Multilangual routes files support#1012vadimv82 wants to merge 6 commits intoplayframework:1.4.xfrom
Conversation
xael-fry
left a comment
There was a problem hiding this comment.
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.
language can be defined on mode character to handle country specific code ex: en_US, en_UK
There was a problem hiding this comment.
@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.
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.
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
| * Main routes file | ||
| */ | ||
| public static VirtualFile routes; | ||
| public static List<VirtualFile> routes; |
There was a problem hiding this comment.
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.