<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Locale::Wolowitz - Dead simple localization with JSON.

SYNOPSIS
            # in ./i18n/locales.coll.json
            {
                    "Welcome!": {
                            "he": "×‘×¨×•×›×™×ť ×”×‘××™×ť!",
                            "es": "Bienvenido!"
                    },
                    "I'm using %1": {
                            "he": "××&nbsp;×™ ×ž×©×Ş×ž×© ×‘%1",
                            "es": "Estoy usando %1"
                    },
                    "Linux": {
                            "he": "×ś×™×&nbsp;×•×§×ˇ"
                    }
            }

            # in your app
            use Locale::Wolowitz;

            my $w = Locale::Wolowitz-&gt;new( './i18n' );

            print $w-&gt;loc('Welcome!', 'es'); # prints 'Bienvenido!'

            print $w-&gt;loc("I'm using %1", 'he', $w-&gt;loc('Linux', 'he')); # prints "××&nbsp;×™ ×ž×©×Ş×ž×© ×‘×ś×™×&nbsp;×•×§×ˇ"

            # you can also directly load data (useful if data is not in files, but say in database)
            $w-&gt;load_structure({
                    hello =&gt; {
                            he =&gt; '×©×ś×•×ť',
                            fr =&gt; 'bonjour'
                    }
            });

            print $w-&gt;loc('hello', 'he'); # prints "×©×ś×•×ť"

DESCRIPTION
    Locale::Wolowitz is a very simple text localization system. Yes, another
    localization system.

    Frankly, I never realized how to use the standard Perl localization
    systems such as Locale::Maketext, Gettext, Data::Localize or whatever.
    It seems they are more meant to localize an application to the language
    of the system on which its running, which isn't really what I need. Most
    of the time, seeing as how I'm mostly writing web applications, I wish
    to localize my applications/websites according to the user's wishes, not
    by the system. For example, I may create a content management system
    where the user can select the interface's language. Also, I grew to hate
    the standard .po files, and thought using a JSON format might be more
    comfortable.

    Locale::Wolowitz allows you to provide different languages to end-users
    of your applications. To some extent, when writing RESTful web
    applications, this means you can perform language negotiation with
    visitors (see Content negotiation on Wikipedia
    &lt;https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Content_neg
    otiation&amp;oldid=367120431&gt;).

    Locale::Wolowitz works with JSON files. Each file can serve one or more
    languages. When creating an instance of this module, you are required to
    pass a path to a directory where your application's JSON localization
    files are present. These are all loaded and merged into one big hash-ref
    (unless you tell the module to only load a specific file), which is
    stored in memory. A file with only one language has to be named
    &lt;lang&gt;.json (where &lt;lang&gt; is the name of the language, you'd probably
    want to use the two-letter ISO 639-1 code). A file with multiple
    languages must end with .coll.json (this requirement will probably be
    lifted in the future).

    The basic idea is to write your application in a base language, and use
    the JSON files to translate text to other languages. For example, lets
    say you're writing your application in English and translating it to
    Hebrew, Spanish, and Dutch. You put Spanish and Dutch translations in
    one file, and since everybody hates Israel, you put Hebrew translations
    alone. The Spanish and Dutch file can look like this:

            # es_and_nl.coll.json
            {
                    "Welcome!": {
                            "es": "Bienvenido!",
                            "nl": "Welkom!"
                    },
                    "I'm using %1": {
                            "es": "Estoy usando %1",
                            "nl": "Ik gebruik %1"
                    },
                    "Linux": {} // this line can also be missing entirely
            }

    While the Hebrew file can look like this:

            # he.json
            {
                    "Welcome!": "×‘×¨×•×›×™×ť ×”×‘××™×ť!",
                    "I'm using %1": "××&nbsp;×™ ×ž×©×Ş×ž×© ×‘%1",
                    "Linux": "×ś×™×&nbsp;×•×§×ˇ"
            }

    When loading these files, Locale::Wolowitz internally merges the two
    files into one structure:

            {
                    "Welcome!" =&gt; {
                            "es" =&gt; "Bienvenido!",
                            "nl" =&gt; "Welkom!",
                            "he" =&gt; "×‘×¨×•×›×™×ť ×”×‘××™×ť!",
                    },
                    "I'm using %1" =&gt; {
                            "es" =&gt; "Estoy usando %1",
                            "nl" =&gt; "Ik gebruik %1",
                            "he" =&gt; "××&nbsp;×™ ×ž×©×Ş×ž×© ×‘%1",
                    },
                    "Linux" =&gt; {
                            "he" =&gt; "×ś×™×&nbsp;×•×§×ˇ",
                    }
            }

    Notice the "%1" substrings above. This is a placeholder, just like in
    other localization paradigms - they are replaced with content you
    provide, usually dynamic content. In Locale::Wolowitz, placeholders are
    written with a percent sign, followed by an integer, starting from 1
    (e.g. %1, %2, %3). When passing data for the placeholders, make sure
    you're passing scalars, or printable objects, otherwise you'll encounter
    errors.

    We can also see here that Spanish and Dutch have no translation for
    "Linux". Since Linux is written "Linux" in these languages, they have no
    translation. When attempting to translate a string that has no
    translation to the requested language, or has no reference in the JSON
    files at all, the string is simply returned as is (but placeholders will
    still be replaced as expected).

    Say you write your application in English (and thus 'en' is your base
    language). Since Locale::Wolowitz doesn't really know what your base
    language is, you can translate texts within the same language. This is
    more useful when you want to give some of your strings an identifier.
    For example:

            "copyrights": {
                    "en": "Copyrights, 2010 Ido Perlmuter",
                    "he": "×›×ś ×”×–×›×•×™×•×Ş ×©×ž×•×¨×•×Ş, 2010 ×˘×™×“×• ×¤×¨×ś×ž×•××¨"
            }

CONSTRUCTOR
  new( [ $path / $filename ] )
    Creates a new instance of this module. A path to a directory in which
    JSON localization files exist, or a path to a specific localization
    file, *may* be supplied. If you pass a directory, all JSON localization
    files in it will be loaded and merged as described above. If you pass
    one file, only that file will be loaded.

    Note that "Locale::Wolowitz" will ignore dotfiles in the provided path
    (e.g. hidden files, backups files, etc.).

OBJECT METHODS
  load_path( $path / $filename )
    Receives a path to a directory in which JSON localization files exist,
    or a path to a specific localization file, and loads (and merges) the
    localization data from the file(s). If localization data was already
    loaded previously, the structure will be merged, with the new data
    taking precedence.

    You can call this method and load_structure() as much as you want, the
    data from each call will be merged with existing data.

  load_structure( \%structure, [ $lang ] )
    Receives a hash-ref of localization data similar to that in the JSON
    files and loads it into the object (possibly merging with existing data,
    if any). If $lang is supplied, a one-to-one structure will be assumed,
    like so:

            load_structure(
                    { "hello" =&gt; "×©×ś×•×ť", "world" =&gt; "×˘×•×ś×ť" },
                    'he'
            )

    Or, if $lang is not provided, the structure must be the multiple
    language structure, like so:

            load_structure({
                    "hello" =&gt; {
                            "he" =&gt; "×©×ś×•×ť",
                            "fr" =&gt; "bonjour"
                    },
                    "world" =&gt; {
                            "he" =&gt; "×˘×•×ś×ť",
                            "fr" =&gt; "monde",
                            "it" =&gt; "mondo"
                    }
            })

    You can call this method and load_path() as much as you want, the data
    from each call will be merged with existing data.

  loc( $msg, $lang, [ @args ] )
    Returns the string $msg, translated to the requested language (if such a
    translation exists, otherwise no traslation occurs). Any other
    parameters passed to the method (@args) are injected to the placeholders
    in the string (if present).

DIAGNOSTICS
    The following exceptions are thrown by this module:

    "You must provide a path to localization directory."
        This exception is thrown if you haven't provided the "new()"
        subroutine a path to a localization file, or a directory of
        localization files. Read the documentation for the "new()"
        subroutine above.

    "Can't open localization directory: %s" and "Can't close localization
    directory: %s"
        This exception is thrown if Locale::Wolowitz failed to open/close
        the directory of the localization files. This will probably happen
        due to permission problems. The error message should include the
        actual reason for the failure.

    "Path must be to a directory or a JSON file."
        This exception is thrown if you passed a wrong value to the "new()"
        subroutine as the path to the localization directory/file. Either
        the path is wrong and thus does not exist, or the path does exist,
        but is not a directory and not a file.

    "Can't open localization file %s: %s" and "Can't close localization file
    %s: %s"
        This exception is thrown if Locale::Wolowitz fails to open/close a
        specific localization file. This will usually happen because of
        permission problems. The error message will include both the name of
        the file, and the actual reason for the failure.

CONFIGURATION AND ENVIRONMENT
    "Locale::Wolowitz" requires no configuration files or environment
    variables.

DEPENDENCIES
    "Locale::Wolowitz" depends on the following CPAN modules:

    *   Carp

    *   JSON::MaybeXS

    "Locale::Wolowitz" recommends Cpanel::JSON::XS or JSON::XS for faster
    parsing of JSON files.

INCOMPATIBILITIES WITH OTHER MODULES
    None reported.

BUGS AND LIMITATIONS
    No bugs have been reported.

    Please report any bugs or feature requests to
    "bug-Locale-Wolowitz@rt.cpan.org", or through the web interface at
    &lt;http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Locale-Wolowitz&gt;.

AUTHOR
    Ido Perlmuter &lt;ido@ido50.net&gt;

LICENSE AND COPYRIGHT
    Copyright (c) 2010-2015, Ido Perlmuter "ido@ido50.net".

    This module is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either version 5.8.1 or any later
    version. See perlartistic and perlgpl.

    The full text of the license can be found in the LICENSE file included
    with this module.

DISCLAIMER OF WARRANTY
    BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
    FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
    OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
    PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
    EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
    ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
    YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
    NECESSARY SERVICING, REPAIR, OR CORRECTION.

    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
    WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
    REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
    TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
    CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
    SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
    RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
    FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
    SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
    DAMAGES.

</pre></body></html>