Locale sample
[1/1] from: mario::cassani::icl::com at: 22-Nov-2001 8:39
Hi all,
I already shared this with Phil Bevan, for his mailer,
it is very simple but IMHO localisation should be introduced
in REBOL apps too so below come my scripts and sample files.
Zaijian and watch line wrap
Mario
8<--------------------------------------------------------------
FILE: %locale.r
================
REBOL [
Title: "Locale library"
Author: "Mario Cassani"
Email: [dmxcas--tin--it]
Date: 10-Oct-2001/15:45:00
File: %locale.r
Version: 0.0.1
Purpose: {Programs easy localisation}
Need: []
History: [
0.0.1 [10-Oct-2001/15:45:00 "First release" "Mario Cassani"]
]
Category: []
]
default-locale: "English"
default-locale-dir: %./locale
locale-load: func [
{Loads localised messages for the application}
idiom [string!] {Idiom to be used}
/locale-path {Specify a different path for locale files}
path-to-locale [path!] {Alternative path}
] [
either [locale-path] [
locale-file: rejoin [default-locale-dir "/" default-locale ".txt"]
locale-file-temp: rejoin [default-locale-dir "/" idiom ".txt"]
] [
locale-file: rejoin [path-to-locale "/" default-locale ".txt"]
locale-file-temp: rejoin [path-to-locale "/" idiom ".txt"]
]
if exists? locale-file-temp [
locale-file: locale-file-temp
]
either exists? locale-file [
do locale-file
] [
return join "Error loading " locale-file
]
]
FILE: locale-demo.r
====================
REBOL [
Title: "Locale Library Demo"
Author: "Mario Cassani"
Email: [dmxcas--tin--it]
Date: 11-Oct-2001/20:30:00
File: %locale-demo.r
Version: 1.0.0
Purpose: {Show Locale Library Usage}
Need: [%locale.r]
History: [
1.0.0 [11-Oct-2001/20:30:00 "First release" "Mario Cassani"]
]
Category: []
]
; *** Open Locale Library
; ========================
do %locale.r
; *** Show function help
? locale-load
; *** Try with an unexisting locale: should default to English
locale-load "Milanes"
print newline
print locale-msg/test_message
; *** Try with an existing locale
locale-load "Italiano"
print newline
print locale-msg/test_message
halt
FILE: %locale/english.txt
==========================
REBOL [
Title: "English Locale"
Date: 10-Oct-2001/15:45:00
]
locale-msg: make object! [
test_message: "Test Message"
gui_menu_New: "New"
gui_menu_Send: "Send"
gui_menu_Contacts: "Contacts"
gui_menu_Folders: "Folders"
gui_menu_Accounts: "Accounts"
gui_menu_Preferences: "Preferences"
gui_menu_Unread: "Unread"
gui_menu_Help: "Help"
gui_menu_About: "About"
gui_button_Read: "Read"
gui_button_Reply: "Reply"
gui_button_Forward: "Forward"
gui_button_Delete: "Delete"
gui_button_Info: "Info"
gui_button_Move: "Move"
gui_button_Fetch_Mail: "Fetch Mail"
gui_label_Remove: "Remove"
gui_label_Account: "Account"
]
FILE: %locale/italiano.txt
===========================
REBOL [
Title: "Italian Locale"
Date: 10-Oct-2001/15:46:00
]
locale-msg: make object! [
test_message: "Messaggio di prova"
gui_menu_New: "Nuovo"
gui_menu_Send: "Spedisci"
gui_menu_Contacts: "Contatti"
gui_menu_Folders: "Folders"
gui_menu_Accounts: "Accounts"
gui_menu_Preferences: "Preferenze"
gui_menu_Unread: "Non letti"
gui_menu_Help: "Aiuto"
gui_menu_About: "A proposito"
gui_button_Read: "Leggi"
gui_button_Reply: "Rispondi"
gui_button_Forward: "Inoltra"
gui_button_Delete: "Cancella"
gui_button_Info: "Info"
gui_button_Move: "Muovi"
gui_button_Fetch_Mail: "Scarica Mail"
gui_label_Remove: "Rimuovi"
gui_label_Account: "Account"
]