Skip to content

Commit

Permalink
I18n & Browser lang
Browse files Browse the repository at this point in the history
  • Loading branch information
vjrj committed Dec 20, 2007
1 parent 35ed99d commit 8b5ea5b
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 92 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2007-12-20 Vicente J. Ruiz Jurado <[email protected]>
* Added browser lang recognition and UI init language takes account of this
and also the user lang if is logged

2007-12-17 Vicente J. Ruiz Jurado <[email protected]>
* TextEditor & I18n
* Translation to English & Spanish
Expand Down
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ continue with the client search dialog
<vjrj> See differences between star-yellow-grey.png and -50.png
--> vjrj
<vjrj> explorer specific problems: fonts antialiasing problem?
<vjrj> Ext localization:
http://groups.google.com/group/gwt-ext/browse_thread/thread/ebec316effea2b80/bfbdadc7239b4e5d?lnk=gst&q=i18n#bfbdadc7239b4e5d
http://extjs.com/forum/showthread.php?t=20160&highlight=localization

MIND-TERM:
--------------------------------------------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions dev-utils/hibernate.reveng.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

<table-filter match-name="globalize_countries"
match-catalog="kune_test" />
<table-filter match-name="globalize_languages"
match-catalog="kune_test" />
<table-filter match-name="globalize_translations"
match-catalog="kune_test" />
</hibernate-reverse-engineering>
</hibernate-reverse-engineering>

23 changes: 16 additions & 7 deletions src/main/java/org/ourproject/kune/app/client/KuneEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.ourproject.kune.platf.client.KunePlatform;
import org.ourproject.kune.platf.client.app.ApplicationBuilder;
import org.ourproject.kune.platf.client.services.I18nUITranslation;
import org.ourproject.kune.platf.client.services.Kune;
import org.ourproject.kune.workspace.client.WorkspaceClientModule;

import to.tipit.gwtlib.FireLog;
Expand All @@ -43,18 +44,26 @@ public KuneEntryPoint() {
public void onModuleLoad() {
final String userHash = Cookies.getCookie("userHash");
FireLog.debug("UserHash: " + userHash);
I18nUITranslation.getInstance().init(new AsyncCallback() {
Kune.I18N.getInitialLanguage(new AsyncCallback() {
public void onFailure(final Throwable caught) {
FireLog.debug("Workspace adaptation to your language failed");
}

public void onSuccess(final Object result) {
I18nUITranslation.getInstance().setLexicon((HashMap) result);
KunePlatform platform = new KunePlatform();
platform.install(new WorkspaceClientModule());
platform.install(new DocsClientModule());
platform.install(new ChatClientModule());
new ApplicationBuilder(platform).build(userHash);
Kune.I18N.getInitialLexicon((String) result, new AsyncCallback() {
public void onFailure(final Throwable caught) {
FireLog.debug("Workspace adaptation to your language failed");
}

public void onSuccess(final Object result) {
I18nUITranslation.getInstance().setLexicon((HashMap) result);
KunePlatform platform = new KunePlatform();
platform.install(new WorkspaceClientModule());
platform.install(new DocsClientModule());
platform.install(new ChatClientModule());
new ApplicationBuilder(platform).build(userHash);
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void doAfter(final HttpServletRequest request, final HttpServletResponse
String userSessionId = request.getSession().getId();
userSession.setHash(userSessionId);
userSession.setBrowserLanguage(request.getLocale().getLanguage());
// TODO: think about: httpServletResponse.sendRedirect(locale) ???
}

public void doBefore(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

public interface I18nService extends RemoteService {

String getInitialLanguage();

/**
* @gwt.typeArgs <java.lang.String,java.lang.String>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface I18nServiceAsync {

void setTranslation(String userHash, String id, String translation, AsyncCallback asyncCallback);

void getInitialLanguage(AsyncCallback callback);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,28 @@ public class I18nUITranslation {
private static final String NOTE_FOR_TRANSLATOR_TAG_BEGIN = " [%NT ";
private static final String NOTE_FOR_TRANSLATOR_TAG_END = "]";
// Also in I18nTranslation
private static final String DEFAULT_LANG = "en";
private static final String UNTRANSLATED_VALUE = null;

private static I18nUITranslation instance;
private HashMap lexicon;
private String currentLanguage;
private I18nChangeListenerCollection i18nChangeListeners;

public void init(final AsyncCallback callback) {
currentLanguage = DEFAULT_LANG;
public void getInitialLanguage(final AsyncCallback callback) {
Location loc = WindowUtils.getLocation();
String locale = loc.getParameter("locale");
if (locale != null) {
// If locale parameter exist, use it
String[] localeSplitted = locale.split("_");
currentLanguage = localeSplitted[0];
} else {
I18nServiceAsync server = I18nService.App.getInstance();
server.getInitialLanguage(callback);
}
}

public void getInitialLexicon(final String initLanguage, final AsyncCallback callback) {
currentLanguage = initLanguage;
I18nServiceAsync server = I18nService.App.getInstance();
server.getLexicon(currentLanguage, callback);
}
Expand Down Expand Up @@ -203,4 +209,5 @@ private void fireI18nLanguageChange() {
i18nChangeListeners.fireI18nLanguageChange();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class Container implements HasId {
private Container parent;

@OneToMany(fetch = FetchType.LAZY)
// , mappedBy = "parent")
private List<Container> childs;

@OneToMany(mappedBy = "container")
Expand All @@ -62,114 +61,126 @@ public class Container implements HasId {
private String typeId;

@OneToMany(cascade = CascadeType.ALL)
private List<Alias> aliases;
private List<ContainerTranslation> containerTranslations;

private String toolName;

private String name;

@ManyToOne(fetch = FetchType.LAZY)
private I18nLanguage language;

public Container(final String parentPath, final String title, final Group group, final String toolName) {
this.name = title;
this.absolutePath = parentPath + SEP + title;
owner = group;
this.toolName = toolName;
this.contents = new ArrayList<Content>();
this.childs = new ArrayList<Container>();
this.name = title;
this.absolutePath = parentPath + SEP + title;
owner = group;
this.toolName = toolName;
this.contents = new ArrayList<Content>();
this.childs = new ArrayList<Container>();
}

public Container() {
this(null, null, null, null);
this(null, null, null, null);
}

public String getName() {
return name;
return name;
}

public void setName(final String name) {
this.name = name;
this.name = name;
}

public Long getParentFolderId() {
return parent != null ? parent.getId() : null;
return parent != null ? parent.getId() : null;
}

public Container getParent() {
return parent;
return parent;
}

public Long getId() {
return id;
return id;
}

public void setId(final Long id) {
this.id = id;
this.id = id;
}

public void setParent(final Container parent) {
this.parent = parent;
this.parent = parent;
}

public List<Container> getChilds() {
return childs;
return childs;
}

public void setChilds(final List<Container> childs) {
this.childs = childs;
this.childs = childs;
}

public String getAbsolutePath() {
return absolutePath;
return absolutePath;
}

public void setAbsolutePath(final String absolutePath) {
this.absolutePath = absolutePath;
this.absolutePath = absolutePath;
}

public List<Alias> getAliases() {
return aliases;
public List<ContainerTranslation> getAliases() {
return containerTranslations;
}

public void setAliases(final List<Alias> aliases) {
this.aliases = aliases;
public void setAliases(final List<ContainerTranslation> containerTranslations) {
this.containerTranslations = containerTranslations;
}

public Group getOwner() {
return owner;
return owner;
}

public void setOwner(final Group owner) {
this.owner = owner;
this.owner = owner;
}

public String getToolName() {
return toolName;
return toolName;
}

public void setToolName(final String toolName) {
this.toolName = toolName;
this.toolName = toolName;
}

public void addContent(final Content descriptor) {
// FIXME: algo de lazy initialization (con size() se arregla...)
contents.size();
contents.add(descriptor);
// FIXME: something related with lazy initialization (workaround using
// size())
contents.size();
contents.add(descriptor);
}

public String getTypeId() {
return typeId;
return typeId;
}

public void setTypeId(final String typeId) {
this.typeId = typeId;
this.typeId = typeId;
}

public List<Content> getContents() {
return contents;
return contents;
}

public void addChild(final Container container) {
childs.size();
childs.add(container);
childs.size();
childs.add(container);
}

public I18nLanguage getLanguage() {
return language;
}

public void setLanguage(final I18nLanguage language) {
this.language = language;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,46 @@
package org.ourproject.kune.platf.server.domain;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "aliases")
public class Alias implements HasId {
public class ContainerTranslation implements HasId {
@Id
@GeneratedValue
private Long id;
private String locale;

@ManyToOne(fetch = FetchType.LAZY)
private I18nLanguage language;

private String name;

public Long getId() {
return id;
return id;
}

public void setId(final Long id) {
this.id = id;
this.id = id;
}

public String getLocale() {
return locale;
public String getName() {
return name;
}

public void setLocale(final String locale) {
this.locale = locale;
public void setName(final String name) {
this.name = name;
}

public String getName() {
return name;
public I18nLanguage getLanguage() {
return language;
}

public void setName(final String name) {
this.name = name;
public void setLanguage(final I18nLanguage language) {
this.language = language;
}

}
Loading

0 comments on commit 8b5ea5b

Please sign in to comment.