Skip to content

Commit

Permalink
Respect languages preferences on login page
Browse files Browse the repository at this point in the history
Fixes #4169
  • Loading branch information
cgx committed May 31, 2017
1 parent 678cf66 commit e73a349
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -16,6 +16,7 @@ Bug fixes
- [core] newly subscribed calendars are excluded from freebusy (#3354)
- [core] strip cr during LDIF import process (#4172)
- [web] fixed mail delegation of pristine user accounts (#4160)
- [web] respect SOGoLanguage and SOGoSupportedLanguages (#4169)
- [eas] fixed opacity in EAS freebusy (#4033)
- [eas] set reply/forwarded flags when ReplaceMime is set (#4133)
- [eas] remove alarms over EAS if we don't want them (#4059)
Expand Down
1 change: 1 addition & 0 deletions SoObjects/SOGo/SOGoDefaults.plist
Expand Up @@ -38,6 +38,7 @@
SOGoEnableDomainBasedUID = NO;

SOGoLoginModule = "Mail";
WODefaultLanguages = ();
SOGoLanguage = "English";
SOGoSupportedLanguages = (
"Arabic",
Expand Down
28 changes: 19 additions & 9 deletions SoObjects/SOGo/WOContext+SOGo.m
Expand Up @@ -26,6 +26,7 @@
#import <NGObjWeb/WOSession.h>

#import "SOGoDomainDefaults.h"
#import "SOGoSystemDefaults.h"
#import "SOGoUser.h"
#import "SOGoUserDefaults.h"

Expand All @@ -36,34 +37,43 @@ @implementation WOContext (SOGoSOPEUtilities)
- (NSArray *) resourceLookupLanguages
{
NSMutableArray *languages;
NSArray *browserLanguages;
NSArray *browserLanguages, *supportedLanguages;
SOGoSystemDefaults *sd;
SOGoUser *user;
NSString *language;

languages = [NSMutableArray array];
user = [self activeUser];

// Retrieve language parameter
language = [[self request] formValueForKey: @"language"];
if ([language length] > 0)
[languages addObject: language];

if (!user || [[user login] isEqualToString: @"anonymous"])
{
// Use browser's languages
browserLanguages = [[self request] browserLanguages];
[languages addObjectsFromArray: browserLanguages];
}
else
{
// Use user's language or domain's language
language = [[user userDefaults] language];
[languages addObject: language];
language = [[user domainDefaults] language];
[languages addObject: language];
}

// if (activeUser && [activeUser language])
// [languages addObject: [activeUser language]];

// if ([self hasSession])
// [languages addObjectsFromArray: [[self session] languages]];
// else
// [languages addObjectsFromArray: [[self request] browserLanguages]];
// Return the first language matching a supported language or the SOGoLanguage
// default if none is matching.
sd = [SOGoSystemDefaults sharedSystemDefaults];
supportedLanguages = [sd supportedLanguages];
language = [languages firstObjectCommonWithArray: supportedLanguages];
if (!(language && [language isKindOfClass: [NSString class]]))
language = [sd stringForKey: @"SOGoLanguage"];

return languages;
return [NSArray arrayWithObject: language];
}

@end
2 changes: 2 additions & 0 deletions UI/MainUI/SOGoRootPage.h
Expand Up @@ -31,6 +31,8 @@
NSString *cookieLogin;
}

- (NSArray *) languages;

@end

#endif /* SOGOROOTPAGE_H */
10 changes: 10 additions & 0 deletions UI/MainUI/SOGoRootPage.m
Expand Up @@ -521,6 +521,16 @@ - (id) item
return item;
}

- (BOOL) hasManyLanguages
{
return [[self languages] count] > 1;
}

- (NSString *) language
{
return [[context resourceLookupLanguages] objectAtIndex: 0];
}

- (NSArray *) languages
{
return [[SOGoSystemDefaults sharedSystemDefaults] supportedLanguages];
Expand Down
4 changes: 3 additions & 1 deletion UI/Templates/MainUI/SOGoRootPage.wox
Expand Up @@ -42,20 +42,22 @@
<label><var:string label:value="Password"/><br/>
<input class="textField" id="password"
name="password" type="password" var:value="password" /></label>
<var:if condition="hasManyLanguages">
<label><var:string label:value="Language"/><br/>
<var:popup const:id="language" const:name="language"
list="languages"
item="item"
var:value="item"
var:selection="language"
string="languageText"
label:noSelectionString="choose"
/></label>
</var:if>
<var:if condition="hasLoginDomains">
<label><var:string label:value="Domain"/><br/>
<var:popup const:id="domain" const:name="domain"
list="loginDomains"
item="item"
var:selection="item"
var:value="item"
string="item"
/></label>
Expand Down
9 changes: 9 additions & 0 deletions UI/WebServerResources/SOGoRootPage.js
Expand Up @@ -24,6 +24,15 @@ function initLogin() {
event.stop() });
}

var language = $("language");
if (language)
language.on("change", function(event) {
var value = $("language").value;
if (value != "WONoSelectionString")
// Reload page
window.location.href = ApplicationBaseURL + '/login?language=' + value;
});

var submit = $("submit");
submit.observe("click", onLoginClick);

Expand Down

0 comments on commit e73a349

Please sign in to comment.