Description

Localization

Author

Kon Lovett

Requires

Usage

(require-extension srfi-29)

Download

srfi-29.egg

Documentation

A Chicken implementation of SRFI 29.

Bundles are assumed stored in the system bundle directory, (repository-path) "srfi-29-bundles".

Within a bundle directory the structure is [LANGUAGE [COUNTRY [SCRIPT [CODESET [MODIFIER]]]]] PACKAGE-NAME.

The default language is en. The default country is us. The locale package will override these if a locale is set. Otherwise the user must set the corresponding parameters.

Any object which can be returned by (read) and tested for equality with equal? is acceptable as a TEMPLATE-NAME. So strings are a valid TEMPLATE-NAME. Further, (localized-template ...) will return any object which can be returned by (read), not just a string.

Aborts with the composite condition (exn srfi-29) and properties location, message, and arguments for errors.

Parameters

parameter: (current-language [LANGUAGE])

Gets or sets the LANGUAGE.

parameter: (current-country [COUNTRY])

Gets or sets the COUNTRY.

parameter: (current-locale-details [LOCALE-DETAILS])

Gets or sets the LOCALE-DETAILS.

parameter: (current-locale-format-function [FORMAT-PROCEDURE])

Gets or sets the FORMAT-PROCEDURE.

Procedures

procedure: (reset-locale-parameters)

If you change the current-locale (see the locale egg), you don't have to set all the current-foo parameters. You can simply call this procedure, and it will update those parameters to the values in the new locale. (Reset as in set anew.)

procedure: (most-specific-bundle-specifier PACKAGE-NAME)

Returns the most specific bundle specifier for the current language, country, and locale details.

procedure: (declare-bundle! BUNDLE-SPECIFIER BUNDLE-ALIST)

Creates a bundle.

procedure: (undeclare-bundle! BUNDLE-SPECIFIER)

Removes the bundle specified by BUNDLE-SPECIFIER from the active bundles.

procedure: (store-bundle! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY])

Writes the bundle.

Uses the ALTERNATE-DIRECTORY if specified.

procedure: (load-bundle! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY])

Reads the bundle.

Uses the ALTERNATE-DIRECTORY if specified.

procedure: (load-best-available-bundle! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY])

Attempts (load-bundle! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY]), from most to least specific.

procedure: (remove-bundle! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY])

Removes the bundle specified by BUNDLE-SPECIFIER from the active bundles, and from the filesystem. The bundle directory is ALTERNATE-DIRECTORY, unless missing. Then the system bundle directory is used.

Will not remove the locale directory hierarchy created by (store-bundle! ...).

procedure: (remove-bundle-directory! BUNDLE-SPECIFIER [ALTERNATE-DIRECTORY])

Removes the bundle directory hierarchy created by (store-bundle! ...). Will only remove empty directories. Returns #t if operation succeeded, #f when a non-empty directory encountered.

Does not remove the bundle, if any, from the active bundles. A filesystem only operation.

This procedure should be used with caution.

procedure: (localized-template PACKAGE-NAME TEMPLATE-NAME [NOT-FOUND #f])

Returns the object for the TEMPLATE-NAME in PACKAGE-NAME, when found, otherwise the NOT-FOUND.

procedure: (localized-template-set! PACKAGE-NAME TEMPLATE-NAME VALUE)

Creates or updates the VALUE for the TEMPLATE-NAME in PACKAGE-NAME and returns #t, when the package exists. Otherwise returns #f.

This can be used to extend the meaning of a package template at runtime. For example: caching the actual closure for a named procedure.

procedure: (localized-template/default PACKAGE-NAME TEMPLATE-NAME [NOT-FOUND TEMPLATE-NAME])

Returns (localized-template PACKAGE-NAME TEMPLATE-NAME NOT-FOUND).

Somewhat like the Posix 'gettext' routine.

procedure: (localized-format PACKAGE-NAME TEMPLATE-NAME PORT ARG0 ...)

Formats the arguments ARG0 ... to the PORT using the (current-locale-format-function) and the format string (localized-template PACKAGE-NAME TEMPLATE-NAME).

When a localized-template is not found and the TEMPLATE-NAME is a string then it is used a the format-string.

A representation is always displayed, even when no template is found. Just not a localized one.

Issues

Possible race condition creating a bundle file or directory.

The locale symbols must have a lowercase printname! As such they do not truly reflect ISO 639-1/2 & ISO 3166-1 standard names. This is a SRFI 29 restriction.

(current-locale-details) is ill-defined by SRFI 29. Which symbol means what? This implementation defines locale details as a 3 element list (SCRIPT CODESET MODIFIER) where the elements are symbols or #f.

Version

License

"Copyright (c) 2005-2008, Kon Lovett.  All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.