use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
use Apache2::Log;
use OpenSRF::EX qw(:try);
-use OpenILS::Utils::CStoreEditor;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
use constant OILS_HTTP_COOKIE_SKIN => 'eg_skin';
use constant OILS_HTTP_COOKIE_THEME => 'eg_theme';
use constant OILS_HTTP_COOKIE_LOCALE => 'eg_locale';
# cache string bundles
-my @registered_locales;
+my %registered_locales;
sub handler {
my $r = shift;
my %locales = $r->dir_config->get('OILSWebLocale');
load_locale_handlers($ctx, %locales);
- $ctx->{locale} =
+ $ctx->{locales} = \%registered_locales;
+
+ # Set a locale cookie if the requested locale is valid
+ my $set_locale = $cgi->param('set_eg_locale');
+ if (!(grep {$_ eq $set_locale} keys %registered_locales)) {
+ $set_locale = '';
+ } else {
+ my $slc = $cgi->cookie({
+ '-name' => OILS_HTTP_COOKIE_LOCALE,
+ '-value' => $set_locale,
+ '-expires' => '+10y'
+ });
+ $r->headers_out->add('Set-Cookie' => $slc);
+ }
+
+ $ctx->{locale} = $set_locale ||
$cgi->cookie(OILS_HTTP_COOKIE_LOCALE) ||
parse_accept_lang($r->headers_in->get('Accept-Language')) || 'en_us';
my $ctx = shift;
my %locales = @_;
+ my $editor = new_editor();
my @locale_tags = sort { length($a) <=> length($b) } keys %locales;
# always fall back to en_us, the assumed template language
for my $idx (0..$#locale_tags) {
my $tag = $locale_tags[$idx];
- next if grep { $_ eq $tag } @registered_locales;
+ next if grep { $_ eq $tag } keys %registered_locales;
+
+ my $res = $editor->json_query({
+ "from" => [
+ "evergreen.get_locale_name",
+ $tag
+ ]
+ });
+
+ my $locale_name = $res->[0]->{"name"} if exists $res->[0]->{"name"};
+ next unless $locale_name;
my $parent_tag = '';
my $sub_idx = $idx;
if ($@) {
warn "$@\n" if $@;
} else {
- push(@registered_locales, $tag);
+ $registered_locales{"$tag"} = $locale_name;
}
}
}
BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0722', :eg_version); -- berick/mrpeters/senator
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0723', :eg_version); -- denials/senator
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
--- /dev/null
+-- Evergreen DB patch 0723.schema.acq-po-state-constraint.sql
+--
+BEGIN;
+
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('0723', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.get_locale_name(
+ IN locale TEXT,
+ OUT name TEXT,
+ OUT description TEXT
+) AS $$
+DECLARE
+ eg_locale TEXT;
+BEGIN
+ eg_locale := LOWER(SUBSTRING(locale FROM 1 FOR 2)) || '-' || UPPER(SUBSTRING(locale FROM 4 FOR 2));
+
+ SELECT i18nc.string INTO name
+ FROM config.i18n_locale i18nl
+ INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation
+ WHERE i18nc.identity_value = eg_locale
+ AND code = eg_locale
+ AND i18nc.fq_field = 'i18n_l.name';
+
+ IF name IS NULL THEN
+ SELECT i18nl.name INTO name
+ FROM config.i18n_locale i18nl
+ WHERE code = eg_locale;
+ END IF;
+
+ SELECT i18nc.string INTO description
+ FROM config.i18n_locale i18nl
+ INNER JOIN config.i18n_core i18nc ON i18nl.code = i18nc.translation
+ WHERE i18nc.identity_value = eg_locale
+ AND code = eg_locale
+ AND i18nc.fq_field = 'i18n_l.description';
+
+ IF description IS NULL THEN
+ SELECT i18nl.description INTO description
+ FROM config.i18n_locale i18nl
+ WHERE code = eg_locale;
+ END IF;
+END;
+$$ LANGUAGE PLPGSQL COST 1 STABLE;
+
+COMMIT;
--- /dev/null
+[%- IF ctx.locales.keys.size > 1;
+ set_locale = CGI.param('set_eg_locale') || CGI.cookie('eg_locale');
+%]
+<form id="locale_picker_form" action="[% mkurl() %]">
+ <label for="locale_picker">[% l("Language:") %]</label>
+ [%- FOREACH param IN CGI.params(); -%]
+ [%- NEXT IF param.key == 'set_eg_locale'; -%]
+ <input type="hidden" name="[% param.key %]" value="[% param.value %]" />
+ [%- END; -%]
+ <select id="locale_picker" name="set_eg_locale">
+ [%- FOREACH locale IN ctx.locales.keys %]
+ [%- IF set_locale == locale;
+ selected = 'selected="selected"';
+ ELSE;
+ selected = '';
+ END;
+ %]
+ <option value="[% locale | html %]" [% selected %]>[% ctx.locales.$locale | html %]</option>
+ [%- END %]
+ </select>
+ <input type="submit" value="[% l("Change") %]" />
+</form>
+[%- END %]
</div>
[% END %]
</div>
+ [%- INCLUDE "opac/parts/locale_picker.tt2" %]
<div class="common-no-pad"></div>
</div>
</div>
border-bottom-style: solid;
}
+#locale_picker_form {
+ float: right;
+ padding: 0.5em 1em 0.5em 0;
+ border-right: thin #69A088 solid;
+}
+
+#locale_picker_form * {
+ margin: 0;
+ padding: 0;
+ vertical-align: middle;
+ font-size: 1em;
+}