Commit 41d16322 authored by Matija Obreza's avatar Matija Obreza
Browse files

Country i18n

parent ee626b41
......@@ -16,17 +16,25 @@
package org.genesys2.server.model.impl;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Locale;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Entity
@Table(name = "country")
@Indexed
......@@ -40,12 +48,19 @@ public class Country extends BusinessModel {
private String codeNum;
private Long refnameId;
/**
* Localized names
*/
private String nameL;
@Transient
private JsonNode nameJ;
public Country() {
}
@Column(nullable = false, unique = true, length = 3)
@Field(name="title")
@Field(name = "title")
public String getCode3() {
return code3;
}
......@@ -54,7 +69,7 @@ public class Country extends BusinessModel {
this.code3 = code3;
}
@Column(unique=false, length = 2)
@Column(unique = false, length = 2)
public String getCode2() {
return this.code2;
}
......@@ -73,7 +88,7 @@ public class Country extends BusinessModel {
}
@Column(unique = false, nullable = false, length = 200)
@Field(name="body", store=Store.NO)
@Field(name = "body", store = Store.NO)
public String getName() {
return this.name;
}
......@@ -99,9 +114,49 @@ public class Country extends BusinessModel {
return refnameId;
}
@Lob
public String getNameL() {
return nameL;
}
public void setNameL(String nameL) {
this.nameL = nameL;
}
public String getName(Locale locale) {
return getNameLocal(locale);
}
public void setName(Locale locale, String name) {
// TODO Fix this
ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
ObjectNode newLang = mapper.createObjectNode().put(locale.getLanguage(), name);
System.err.println(newLang);
} catch (IOException e) {
}
}
private synchronized String getNameLocal(Locale locale) {
if (this.nameJ == null && this.nameL != null) {
System.err.println("Parsing nameL=" + nameL);
ObjectMapper mapper = new ObjectMapper();
try {
this.nameJ = mapper.readTree(nameL);
if (this.nameJ != null) {
System.err.println(">>> " + this.nameJ + " " + this.nameJ);
}
} catch (IOException e) {
e.printStackTrace();
}
}
return this.nameJ != null && this.nameJ.has(locale.getLanguage()) ? this.nameJ.get(locale.getLanguage()).textValue() : this.name;
}
@Override
public String toString() {
return MessageFormat.format("Country id={0} name={1} current={2}", id,
name, current);
return MessageFormat.format("Country id={0} name={1} current={2}", id, name, current);
}
}
......@@ -43,4 +43,6 @@ public interface GeoService {
void updateBlurp(Country country, String blurp, Locale locale);
List<Country> listAll(Locale locale);
}
......@@ -17,6 +17,8 @@
package org.genesys2.server.service.impl;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
......@@ -47,12 +49,23 @@ public class GeoServiceImpl implements GeoService {
@Autowired
ContentService contentService;
@Override
public List<Country> listAll() {
return countryRepository.findAll(new Sort("name", "current"));
}
@Override
public List<Country> listAll(final Locale locale) {
List<Country> all = listAll();
Collections.sort(all, new Comparator<Country>() {
@Override
public int compare(Country o1, Country o2) {
return o1.getName(locale).compareTo(o2.getName(locale));
}
});
return all;
}
@Override
public Country getCountry(String countryString) {
Country country = null;
......@@ -191,12 +204,11 @@ public class GeoServiceImpl implements GeoService {
}
}
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateBlurp(Country country, String blurp, Locale locale) {
contentService.updateArticle(country, "blurp", null, blurp, locale);
contentService.updateArticle(country, "blurp", null, blurp, locale);
}
}
......@@ -57,7 +57,7 @@ public class CountryController extends BaseController {
@RequestMapping
public String view(ModelMap model) {
model.addAttribute("countries", geoService.listAll());
model.addAttribute("countries", geoService.listAll(getLocale()));
return "/country/index";
}
......
......@@ -47,6 +47,8 @@ save=Save
cancel=Cancel
delete=Delete
jump-to-top=Back to top!
pagination.next-page=Next >
pagination.previous-page=< Previous
......
......@@ -4,11 +4,11 @@
<html>
<head>
<title><spring:message code="country.page.profile.title" arguments="${country.name}" argumentSeparator="|" /></title>
<title><spring:message code="country.page.profile.title" arguments="${country.getName(pageContext.response.locale)}" argumentSeparator="|" /></title>
</head>
<body>
<h1>
<c:out value="${country.name}" />
<c:out value="${country.getName(pageContext.response.locale)}" />
<img class="country-flag bigger" src="http://genesys-pgr.org/images/flags/${country.code3.toUpperCase()}.png" />
</h1>
......
......@@ -14,8 +14,8 @@
<div id="letter-top" class="page-header">
<c:set value="" var="hoofdleter" />
<c:forEach items="${countries}" var="country" varStatus="status">
<c:if test="${hoofdleter ne country.name.substring(0, 1)}">
<c:set var="hoofdleter" value="${country.name.substring(0, 1)}" />
<c:if test="${hoofdleter ne country.getName(pageContext.response.locale).substring(0, 1)}">
<c:set var="hoofdleter" value="${country.getName(pageContext.response.locale).substring(0, 1)}" />
<a class="letter-pointer" href="#letter-${hoofdleter}"><c:out value="${hoofdleter}" /></a>
</c:if>
</c:forEach>
......@@ -26,12 +26,12 @@
<ul class="funny-list">
<c:forEach items="${countries}" var="country" varStatus="status">
<c:if test="${hoofdleter ne country.name.substring(0, 1)}">
<c:set var="hoofdleter" value="${country.name.substring(0, 1)}" />
<c:set var="hoofdleter" value="${country.getName(pageContext.response.locale).substring(0, 1)}" />
<li id="letter-${hoofdleter}" class="hoofdleter"><c:out value="${hoofdleter}" />
<small><a href="#letter-top">Back to top</a></small>
<small><a href="#letter-top"><spring:message code="jump-to-top" /></a></small>
</li>
</c:if>
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}"><a class="show ${not country.current ? 'disabled' : ''}" href="<c:url value="/geo/${country.code3.toLowerCase()}" />"><c:out value="${country.name}" /></a></li>
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}"><a class="show ${not country.current ? 'disabled' : ''}" href="<c:url value="/geo/${country.code3.toLowerCase()}" />"><c:out value="${country.getName(pageContext.response.locale)}" /></a></li>
</c:forEach>
</ul>
<c:remove var="hoofdleter" />
......
......@@ -236,11 +236,16 @@ li.hoofdleter {
margin: 1em 0 0.5em;
}
li.hoofdleter small {
html:not([dir="rtl"]) li.hoofdleter small {
font-size: 10px;
margin-left: 3em;
}
html[dir="rtl"] li.hoofdleter small {
font-size: 10px;
margin-right: 3em;
}
.letter-pointer {
padding: 0 0.7em;
font-weight: bold;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment