Skip to content

Commit

Permalink
SAK-29422 Switch I18n implementation to use ResourceLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
marktriggs committed Jun 23, 2015
1 parent d81e29b commit d71e938
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public interface PASystem {
/**
* Return an I18N translator for a given file and locale.
*/
public I18n getI18n(ClassLoader loader, String resourceBase, Locale locale);
public I18n getI18n(ClassLoader loader, String resourceBase);
}

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.sakaiproject.authz.cover.FunctionManager;
Expand All @@ -51,7 +50,7 @@
import org.sakaiproject.pasystem.api.Popup;
import org.sakaiproject.pasystem.api.Popups;
import org.sakaiproject.pasystem.impl.banners.BannerStorage;
import org.sakaiproject.pasystem.impl.common.JSONI18n;
import org.sakaiproject.pasystem.impl.common.SakaiI18n;
import org.sakaiproject.pasystem.impl.popups.PopupForUser;
import org.sakaiproject.pasystem.impl.popups.PopupStorage;
import org.sakaiproject.portal.util.PortalUtils;
Expand All @@ -73,17 +72,13 @@ class PASystemImpl implements PASystem {

private static final String POPUP_SCREEN_SHOWN = "pasystem.popup.screen.shown";

private Map<String, I18n> i18nStore;

@Override
public void init() {
if (ServerConfigurationService.getBoolean("auto.ddl", false) || ServerConfigurationService.getBoolean("pasystem.auto.ddl", false)) {
runDBMigration(ServerConfigurationService.getString("[email protected]"));
}

FunctionManager.registerFunction("pasystem.manage");

i18nStore = new ConcurrentHashMap<String, I18n>(1);
}

@Override
Expand All @@ -94,8 +89,7 @@ public void destroy() {
public String getFooter() {
StringBuilder result = new StringBuilder();

Locale userLocale = PreferencesService.getLocale(SessionManager.getCurrentSessionUserId());
I18n i18n = getI18n(this.getClass().getClassLoader(), "i18n", userLocale);
I18n i18n = getI18n(this.getClass().getClassLoader(), "org.sakaiproject.pasystem.impl.i18n.pasystem");
Handlebars handlebars = loadHandleBars(i18n);

Session session = SessionManager.getCurrentSession();
Expand Down Expand Up @@ -132,20 +126,8 @@ public Popups getPopups() {
}

@Override
public I18n getI18n(ClassLoader loader, String resourceBase, Locale locale) {
String language = "en";

if (locale != null) {
language = locale.getLanguage();
}

String i18nKey = resourceBase + "::" + language + "::" + loader.hashCode();

if (!i18nStore.containsKey(i18nKey)) {
i18nStore.put(i18nKey, new JSONI18n(loader, resourceBase, locale));
}

return i18nStore.get(i18nKey);
public I18n getI18n(ClassLoader loader, String resourceBase) {
return new SakaiI18n(loader, resourceBase);
}

private Handlebars loadHandleBars(final I18n i18n) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**********************************************************************************
*
* Copyright (c) 2015 The Sakai Foundation
*
* Original developers:
*
* New York University
* Payten Giles
* Mark Triggs
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************************/

package org.sakaiproject.pasystem.impl.common;

import java.util.MissingResourceException;
import org.sakaiproject.pasystem.api.I18n;
import org.sakaiproject.util.ResourceLoader;

/**
* An I18N implementation based on Sakai's ResourceLoader.
*/
public class SakaiI18n implements I18n {

private ResourceLoader resourceLoader;

public SakaiI18n(ClassLoader loader, String resourceBase) {
resourceLoader = new ResourceLoader(resourceBase, loader);
}

@Override
public String t(String key) {
String result = resourceLoader.getString(key);

if (result == null) {
throw new RuntimeException("Missing translation for key: " + key);
}

return result;
}
}
6 changes: 0 additions & 6 deletions pasystem/pasystem-impl/impl/src/resources/i18n/default.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
popup-acknowledged=Don't show this again
popup-remind-later=Remind me later
Show\ System\ Alerts=Show System Alerts
timezone-does-not-match-msg=Your computer's time zone <span class="computerTimezone">${reportedTimezone}</span> does not match your account's time zone of <span class="prefsTimezone">${prefsTimezone}</span>. <span class="pasystem-tz-click-here"><a href="${setTimezoneUrl}" id="setTimezoneMsg">Click here to update your time zone preferences</a></span>.
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
checkAccessControl();

Locale userLocale = PreferencesService.getLocale(SessionManager.getCurrentSessionUserId());
I18n i18n = paSystem.getI18n(this.getClass().getClassLoader(), "org/sakaiproject/pasystem/tool/i18n", userLocale);
I18n i18n = paSystem.getI18n(this.getClass().getClassLoader(), "org.sakaiproject.pasystem.tool.i18n.pasystem");

response.setHeader("Content-Type", "text/html");

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Active=Active
Are\ you\ sure\ you\ want\ to\ delete\ this\ banner?=Are you sure you want to delete this banner?
Are\ you\ sure\ you\ want\ to\ delete\ this\ popup?=Are you sure you want to delete this popup?
Banners=Banners
Cancel=Cancel
Close=Close
Create\ Banner=Create Banner
Create\ Popup=Create Popup
Delete\ Banner=Delete Banner
Delete\ Popup=Delete Popup
Description=Description
Dismissible=Dismissible
Distribution=Distribution
Edit=Edit
End\ Time=End Time
From=From
Hosts=Hosts
Message=Message
Popups=Popups
Preview=Preview
Save\ Banner=Save Banner
Save\ Popup=Save Popup
Start\ Time=Start Time
Template=Template
Timezone\ Check=Timezone Check
Type=Type
Until=Until
banner_created=Banner Created
banner_deleted=Banner Deleted
banner_type_help=Note: When a user dismisses a "Medium" alert, a small "Show System Alerts" button will remain at the top of their screen. Clicking on this button will cause all active Medium alerts to reappear for the user.
banner_type_high=High
banner_type_high_option=High - Cannot be dismissed by user
banner_type_low=Low
banner_type_low_option=Low - Can be permanently dismissed by user
banner_type_medium=Medium
banner_type_medium_option=Medium - Can be temporarily dismissed by user; reappears after 24 hours
banner_updated=Banner Updated
distribution_everyone=Show this campaign to everyone
distribution_selected_users=Show this campaign to selected users
invalid_time=Time was not valid
pasystem-disabled=The Public Announcement System has not been enabled. Set <tt>pasystem.enabled=true</tt> in your properties file to activate it.
popup_created=Popup Created
popup_deleted=Popup Deleted
popup_updated=Popup Updated
start_time_after_end_time=Start time must fall before end time
template_upload_failed=Template file failed to upload
template_was_missing=Could not find a template for the selected popup screen
timezone-check-active=Timezone checking is <strong>active</strong>
timezone-check-disabled=Timezone checking is <strong>disabled</strong>. Set <tt>pasystem.timezone-check=true</tt> in your properties file to activate it.
uuid_missing=The requested record could not be found

0 comments on commit d71e938

Please sign in to comment.