You are looking at historical revision 15723 of this page. It may differ significantly from its current revision.

srfi-29

A Chicken implementation of SRFI 29.

The addition of the escape code ~[n]@* to the SRFI 28 format is not part of this extention.

Documentation

Parameters

current-language

[parameter] (current-language [LANGUAGE])

Gets or sets the LANGUAGE symbol.

current-country

[parameter] (current-country [COUNTRY])

Gets or sets the COUNTRY symbol.

current-locale-details

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

Gets or sets the LOCALE-DETAILS list.

current-locale-format-function

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

Gets or sets the FORMAT-PROCEDURE.

This procedure must at least have the signature of a SRFI 28 format procedure. The default is the Chicken format procedure.

reset-locale-parameters

[procedure] (reset-locale-parameters)

When the current-locale is changed, (see the locale egg), the current-* parameters need not be set individually. This will update those parameters to the values in the new locale. (Reset as in set anew.)

Bundle Operations

A BUNDLE-SPECIFIER is a list of symbols of the form (PACKAGE-NAME [LANGUAGE] [COUNTRY] [DETAILS...]).

A BUNDLE-ALIST is a list composed of pairs of the form (TEMPLATE-NAME . TEMPLATE-VALUE).

A TEMPLATE-NAME is something suitable as a key, such as a symbol or string, but maybe any object.

A TEMPLATE-VALUE maybe any object.

Note that while a TEMPLATE-NAME and TEMPLATE-VALUE can be any object they really should belong to the set of objects with a unique print-form.

declare-bundle!

[procedure] (declare-bundle! BUNDLE-SPECIFIER BUNDLE-ALIST)

Creates a bundle.

undeclare-bundle!

[procedure] (undeclare-bundle! BUNDLE-SPECIFIER)

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

Bundle Database Operations

While SRFI 29 does not specify how bundles are stored. This extension uses the filesystem is used for the bundle database.

Bundles are stored in the system bundle directory, (repository-path) "srfi-29-bundles", unless an ALTERNATE directory is specified. Within a bundle directory the structure is [LANGUAGE [COUNTRY [SCRIPT [CODESET [MODIFIER]]]]] PACKAGE-NAME.

store-bundle!

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

Stores the bundle using the write procedure.

load-bundle!

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

Loads the bundle using the read procedure.

load-best-available-bundle!

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

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

See most-specific-bundle-specifier.

remove-bundle!

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

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

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

remove-bundle-directory!

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

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.

declared-bundle-specifiers

[procedure] (declared-bundle-specifiers) => LIST

Returns a list of all the declared BUNDLE-SPECIFIERs.

declared-bundle-templates

[procedure] (declared-bundle-templates BUNDLE-SPECIFIER) => LIST

Returns an association-list of all the templates for the BUNDLE-SPECIFIER.

most-specific-bundle-specifier

[procedure] (most-specific-bundle-specifier PACKAGE-NAME) => BUNDLE-SPECIFIER

Returns the most specific bundle specifier for the current locale.

The current locale is composed of the (current-language), (current-country), and (current-locale-details).

Note that the most-specific-bundle-specifier may not be a declared bundle.

Bundle Template Operations

These routines will use the most specific declared bundle for the package PACKAGE-NAME in the current locale.

localized-template

[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 value.

localized-template/default

[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.

localized-format

[procedure] (localized-format PACKAGE-NAME TEMPLATE-NAME ARG0...) => STRING

Returns the formatted string using the (current-locale-format-function) and the format string (localized-template PACKAGE-NAME TEMPLATE-NAME) on the arguments ARG0....

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.

localized-template-set!

[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.

localized-templates

[procedure] (localized-templates PACKAGE-NAME) => LIST

Returns an association-list of all the templates for the PACKAGE-NAME.

Exceptions

Usage

(require-extension srfi-29)

Examples

Notes

Requirements

lookup-table miscmacros locale check-errors

Bugs and Limitations

Author

kon lovett

Version history

2.0.0
Intitial Chicken 4 release. Added introspection routines. Removed PORT parameter for localized-format.

License

Copyright (C) 2009 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.