mirror of
https://github.com/dani/vroom.git
synced 2024-06-29 15:03:41 +02:00
Detect supported lang based on files in I18N
This commit is contained in:
parent
4ae712f060
commit
2d8a599cc6
|
@ -30,7 +30,7 @@
|
||||||
<% } %>
|
<% } %>
|
||||||
<li class="hidden-xs">
|
<li class="hidden-xs">
|
||||||
<select class="form-control navbar-btn" id="switch_lang">
|
<select class="form-control navbar-btn" id="switch_lang">
|
||||||
<% foreach my $lang (qw(en fr)){ %>
|
<% foreach my $lang ($self->get_supported_lang){ %>
|
||||||
<option value="<%= $lang %>" <%= ($self->languages eq $lang) ? 'selected="selected"' : '' %>>
|
<option value="<%= $lang %>" <%= ($self->languages eq $lang) ? 'selected="selected"' : '' %>>
|
||||||
<%= $lang %>
|
<%= $lang %>
|
||||||
</option>
|
</option>
|
||||||
|
|
15
vroom.pl
15
vroom.pl
|
@ -22,6 +22,7 @@ use Email::Valid;
|
||||||
use Protocol::SocketIO::Handshake;
|
use Protocol::SocketIO::Handshake;
|
||||||
use Protocol::SocketIO::Message;
|
use Protocol::SocketIO::Message;
|
||||||
use File::Path qw(make_path);
|
use File::Path qw(make_path);
|
||||||
|
use File::Basename;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
app->log->level('info');
|
app->log->level('info');
|
||||||
|
@ -57,15 +58,11 @@ our $error = undef;
|
||||||
# Global peers hash
|
# Global peers hash
|
||||||
our $peers = {};
|
our $peers = {};
|
||||||
|
|
||||||
# Load I18N, and declare supported languages
|
# Initialize localization
|
||||||
plugin I18N => {
|
plugin I18N => {
|
||||||
namespace => 'Vroom::I18N',
|
namespace => 'Vroom::I18N',
|
||||||
};
|
};
|
||||||
|
|
||||||
# Supported languages must be declared here
|
|
||||||
# Used to generate the dropdown menu
|
|
||||||
our @supported_lang = qw(en fr);
|
|
||||||
|
|
||||||
# Connect to the database
|
# Connect to the database
|
||||||
# Only MySQL supported for now
|
# Only MySQL supported for now
|
||||||
plugin database => {
|
plugin database => {
|
||||||
|
@ -453,6 +450,12 @@ helper update_room_last_activity => sub {
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Return an array of supported languages
|
||||||
|
helper get_supported_lang => sub {
|
||||||
|
my $self = shift;
|
||||||
|
return map { basename(s/\.pm$//r) } glob('lib/Vroom/I18N/*.pm');
|
||||||
|
};
|
||||||
|
|
||||||
# Generate a random token
|
# Generate a random token
|
||||||
helper get_random => sub {
|
helper get_random => sub {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -1408,7 +1411,7 @@ any '/api' => sub {
|
||||||
}
|
}
|
||||||
# Handle requests authorized for anonymous users righ now
|
# Handle requests authorized for anonymous users righ now
|
||||||
if ($req->{action} eq 'switch_lang'){
|
if ($req->{action} eq 'switch_lang'){
|
||||||
if (!grep { $req->{param}->{language} eq $_ } @supported_lang){
|
if (!grep { $req->{param}->{language} eq $_ } $self->get_supported_lang()){
|
||||||
return $self->render(
|
return $self->render(
|
||||||
json => {
|
json => {
|
||||||
msg => $self->l('UNSUPPORTED_LANG'),
|
msg => $self->l('UNSUPPORTED_LANG'),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user