Ado

 view release on metacpan or  search on metacpan

lib/Ado/Plugin/I18n.pm  view on Meta::CPAN


=head1 METHODS

L<Ado::Plugin::I18n> inherits all methods from
L<Ado::Plugin> and implements the following new ones.


=head2 register

This method is called by C<$app-E<gt>plugin>.
Registers the plugin in L<Ado> application and merges internationalization
and localization configuration from C<$MOJO_HOME/etc/ado.conf> with settings
defined in C<$MOJO_HOME/etc/plugins/i18n.conf>. Authentication settings
defined in C<ado.conf> will overwrite those defined in C<plugins/i18n.conf>.
Returns C<$self>.

=head2 routes

Returns a list of routes with C<:language> placeholder
defined in the plugin configuration. Called in L</register>.
To create your own routes just create C<etc/plugin/i18n.conf> and add them to it.
They will replace the default routes.

  #default routes including language placeholder.
  $app->load_routes($self->routes);

  /:language                          GET,OPTIONS
  /:language/:controller              GET,OPTIONS
  /:language/:controller/:action      GET,POST,OPTIONS
  /:language/:controller/:action/:id  GET,PUT,DELETE,OPTIONS

=head2 language

This is the underlying subroutine used in C<around_action> hook and c<language>
helper.

    #Add helpers
    $app->helper(language => \&language);

=head2 around_action

This method is passed as reference to be used as L<Mojolicious/around_action>.

    # Add hook around_action
    $app->hook(around_action => \&around_action);

=head1 TODO

Create a table with message entries which will be loaded by this plugin.

Create user interface to add/edit entries.

=head1 SEE ALSO

L<Locale::Maketext>, L<Ado::Plugin>, L<Ado::Manual::Plugins>,
L<Mojolicious::Plugins>,
L<Mojolicious::Plugin>, L<Mojolicious::Guides::Routing/Conditions>

=head1 SPONSORS

The original author

=head1 AUTHOR

Красимир Беров (Krasimir Berov)

=head1 COPYRIGHT AND LICENSE

Copyright 2014 Красимир Беров (Krasimir Berov).

This program is free software, you can redistribute it and/or
modify it under the terms of the
GNU Lesser General Public License v3 (LGPL-3.0).
You may copy, distribute and modify the software provided that
modifications are open source. However, software that includes
the license may release under a different license.

See http://opensource.org/licenses/lgpl-3.0.html for more information.

=cut

__DATA__

@@ partials/language_menu.html.ep
%# This template is inflated from Ado::Plugin::I18n.
%# It Displays menu items with flags.
%# You can experiment and make it as one dropdown menu item.
%# See http://localhost:3000/perldoc/Ado/Plugin/I18n#partialslanguage_menuhtmlep
% my $stash = $self->stash;
% my $conf = config('Ado::Plugin::I18n');
% my @languages = @{$conf->{languages}};
% $language_from ||= 'route';
% #$c->debug('$language_from:' . $language_from);
% $language ||= $conf->{default_language};

<!-- language_menu start -->
<!-- language_from: <%=$language_from%> -->
<% head_css([$sui_path.'/menu.min.css', $sui_path.'/dropdown.min.css',
    $sui_path.'/item.min.css',$sui_path.'/icon.min.css',
    $sui_path.'/button.min.css']);
 head_javascript($sui_path.'/dropdown.min.js'); %>
<div class="right compact menu" id="language_menu">
<div class="ui simple dropdown item">
  <i class="translate icon"></i><%=l('Translate') %>
  <div class="menu">

% if($language_from eq 'route') {
%   foreach my $l(@languages) {
%     my $active = $l eq $language ? 'active ' : '';
%     my $url = url_for(language => $l, ($$stash{id}?(id => $$stash{id}):()));
%=    link_to $url,(class => "${active}button item", title => l($l) ), begin
%=      l($l)
%=    end
%   }
% }
% elsif($language_from eq 'host'){
%   foreach my $l(@languages){
%     my $active = $l eq $language ? 'active ' : '';
%     my $url = $self->req->url->to_abs->clone;
%     my ($port, $host) = ($url->port,$url->host);
%     $host =~ s|^\w{2}\.||;



( run in 1.524 second using v1.01-cache-2.11-cpan-5837b0d9d2c )