App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Glib/Ex/MoreUtils.pm  view on Meta::CPAN

  my $default = $_[1];

  foreach my $lang (Glib::get_language_names()) {
    if (exists $choices{$lang}) {
      return $choices{$lang};
    }
  }
  return $default;
}

1;
__END__

=for stopwords Ryde userdata

=head1 NAME

App::Chart::Glib::Ex::MoreUtils -- more Glib utility functions

=head1 SYNOPSIS

 use App::Chart::Glib::Ex::MoreUtils;

=head1 FUNCTIONS

=over 4

=item C<< App::Chart::Glib::Ex::MoreUtils::ref_weak ($obj) >>

Return a reference to a weak reference to C<$obj>.  This is good for the
"userdata" in signal connections etc when you want some weakening so you
don't keep C<$obj> alive forever due to the connection.  For example,

    $model->signal_connect (row_deleted, \&deleted_handler,
                            App::Chart::Glib::Ex::MoreUtils::ref_weak($self));

    sub deleted_handler {
      my ($model, $path, $ref_weak_self) = @_;
      my $self = $$ref_weak_self || return;
      ...
    }

=item C<< App::Chart::Glib::Ex::MoreUtils::lang_select ($lang => $value, ...) >>

Choose a value according to the user's preferred language.  Each C<$lang>
argument is a two-letter language code like "en".  The C<$value> arguments
are any scalars to return.  For example

    App::Chart::Glib::Ex::MoreUtils::lang_select (de => 'deutsch',
                                      en => 'english')
    # returns either 'deutsch' or 'english'

The user's preferred language is taken from C<Glib::get_language_names> (see
L<Glib::Utils>).  If none of the given C<$lang> values are among the user's
preferences then the first in the call is used as the default and its
C<$value> returned.

This is meant for selecting semi-technical things from a fixed set of
possibilities within the program code, for example different URLs for the
English or German version of some web page which will be parsed.  If it was
in a F<.mo> file (per C<Locale::TextDomain>) the choice would be locked down
by the translator, but C<lang_select> allows a user preference.

=back

=head1 SEE ALSO

L<Glib::Utils>

=cut



( run in 0.636 second using v1.01-cache-2.11-cpan-e1769b4cff6 )