From 6d78339d362fcdae513ed8834e76fca296eb062b Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 21 Aug 2008 17:25:46 +0000 Subject: [PATCH] added a utility method to find a user's locale git-svn-id: svn://svn.open-ils.org/ILS/trunk@10404 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/AppUtils.pm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 91237b4114..61c3f62abb 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -1452,5 +1452,26 @@ sub get_org_full_path { return \@orgs; } +# returns the user's configured locale as a string. Defaults to en-US if none is configured. +sub get_user_locale { + my($self, $user_id, $e) = @_; + $e ||=OpenILS::Utils::CStoreEditor->new; + + # first, see if the user has an explicit locale set + my $setting = $e->search_actor_user_setting( + {usr => $user_id, name => 'global.locale'})->[0]; + return OpenSRF::Utils::JSON->JSON2perl($setting->value) if $setting; + + my $user = $e->retrieve_actor_user($user_id) or return $e->event; + + # next see if their home org specifies a default locale + $setting = $e->search_actor_org_unit_setting( + {org_unit => $user->home_ou, name => 'global.default_locale'})->[0]; + return OpenSRF::Utils::JSON->JSON2perl($setting->value) if $setting; + + # if nothing else, fallback to locale=cowboy + return 'en-US'; +} + 1; -- 2.43.2