跳轉到內容

Aros/開發者/文件/庫/語言環境

來自華夏公益教科書,開放書籍,開放世界
Aros 華夏公益教科書導航欄
Aros 使用者
Aros 使用者文件
Aros 使用者常見問題解答
Aros 使用者應用程式
Aros 使用者 DOS Shell
Aros/使用者/AmigaLegacy
Aros 開發文件
Aros 開發者文件
從 AmigaOS/SDL 移植軟體
針對 Zune 初學者
Zune .MUI 類
針對 SDL 初學者
Aros 開發者構建系統
特定平臺
Aros x86 完整系統 HCL
Aros x86 音訊/影片支援
Aros x86 網路支援
Aros Intel AMD x86 安裝
Aros 儲存支援 IDE SATA 等
Aros Poseidon USB 支援
x86-64 支援
摩托羅拉 68k Amiga 支援
Linux 和 FreeBSD 支援
Windows Mingw 和 MacOSX 支援
Android 支援
Arm Raspberry Pi 支援
PPC Power Architecture
其他
Aros 公共許可證

這裡有一個全域性環境變數(Language),它儲存著當前活動的語言。

您可以透過在 Shell 中鍵入“getenv language”(不帶引號)來檢查它。或者它可以在指令碼中用作變數 $Language。

它也可以透過程式設計使用 OpenLocale() 函式完成(使用 NULL 作為引數以返回結構 Locale 中的當前語言環境資訊)。

locale.library 為我們提供了本地化應用程式的工具。本地化字串儲存在單獨的語言目錄檔案(在 Catalogs 目錄下)中。AROS 開發環境宏可以構建所需的檔案。本文件為您提供了一個工作流程,用於本地化應用程式或本地化現有應用程式,或為現有本地化應用程式建立目錄檔案。

對於系統支援的每種語言,系統都有一個 LOCALE:Languages/ 檔案

LOCALE:Languages/klingon.language

系統翻譯位於 LOCALE:Catalogs/ language 目錄中

LOCALE:Catalogs/klingon/

每個應用程式都需要其適當的 Catalogs 目錄

my_app/Catalogs/

翻譯檔案位於 language 目錄中

my_app/Catalogs/klingon/my_app.catalog

應用程式

[編輯 | 編輯原始碼]

每個支援本地化的應用程式都有自己的 catalogs 目錄

AROS/Contrib/my_app/catalogs

字串最初儲存在目錄描述檔案中

AROS/Contrib/my_app/catalogs/my_app.cd
This file is structured as:
;
MSG_TITLE (//)
My Application
;
MSG_MY_MESSAGE (//)
My application message
;
...

翻譯儲存在目錄翻譯檔案中

AROS/Contrib/my_app/catalogs/klingon.ct

結構如下

## version $VER: my_app.catalog 1.0 (23.05.2004)
## language klingon
## codeset 0
;
MSG_TITLE
tlhIngan maH
;
MSG_MY_MESSAGE
Sujatlh 'e' yImev
;
...

目錄構建檔案

本地化由以下提供

AROS/Contrib/my_app/locale.c
AROS/contrib/my_app/locale.h

應用程式:_(MSG_MY_TITLE)

作為 STRPTR。

或使用:__(MSG_MY_MESSAGE)

作為 IPTR(1) 應用程式原始檔

在 AROS/Contrib/my_app/my_app.c 中,使用以下命令初始化語言環境

...

#include "locale.h"

main()
{

...

使用 .cd 檔案中的字串名稱。例如,在 Zune 應用程式中:MUIA_Application_Title, __(MSG_TITLE), ... } 應用程式構建檔案

Add the locale file target to the FILE section of AROS/Contrib/my_app/mmakefile.src:
FILES    := my_app \
               ...
               locale

Add the pre-requisite target for locale:
#MM- my_app: \
  ...
#MM my_app-catalogs
Build the locale
AROS/

To build the application and locale files:
make my_app

To update the translation (.ct) files:
make my_app-catalogsWarning:	If you are updating the description (.cd) files, build my_app target to update its strings file.

構建系統

[編輯 | 編輯原始碼]

AROS Metamake 使用其構建檔案(存在於以下位置)構建所需檔案

AROS/Contrib/my_app/catalogs/mmakefile.src
# Copyright © 2004, The AROS Development Team. All rights reserved.
# $Id: mmakefile.src,v 1.2 2004/02/19 22:05:38 john doe Exp $

include $(TOP)/config/make.cfg

%build_catalogs mmake=my_app-catalogs \
  name=My_App \
  subdir= \
  dir=$(AROSDIR)/Extras/My_App/Catalogs
Application directory
AROS/Contrib/my_app/

FlexCat 是一種用於建立 Amiga 本地化目錄以及原始檔和標頭檔案的工具,這些檔案來自於目錄描述。

AROS/tools 中的版本是 2.4,開發人員的 readme 檔案說明將其視為免費軟體(包含原始碼),但不要進行分支。歷史記錄檔案告訴我們,2.4 版來自 1999 年 11 月 28 日。文件中提到的並非所有網站都仍然存在,但 flexcat 確實支援 2.4 版,並且沒有提到進一步的開發。移植是否算分支?如果沒有,那麼一個以前的移植是否算分支(例如,僅僅因為 AROS 成為 68k)?如果最初只有一個移植,但其他人做了另一個移植 - 誰是分支者?也許作者只是太不精確了,應該提供分支的定義……

1 AROS 專案的戳記是 2009 年 3 月 7 日,因此過去十年中 AROS 版本可能發生了變化。

2 Aminet 上的最後一個版本是 2010 年 6 月 29 日釋出的 2.7 版,由 專案 釋出,該專案聲稱版權始於 2002 年。

原始主頁 已過時。它現在是一個使用 GPL 許可的 產品,在這裡維護。當然,2.7 發行版不包含原始碼,因為該專案是開源的,並且 原始碼 對所有人開放。發行版存檔僅包含所有支援平臺的二進位制檔案。

  • 從 FlexCat 的穩定版本更新 AROS 中的原始碼
  • 使其再次可構建,也許我可以從之前的提交中合併提交。
  • C_h_orig.sd 在當前的 FlexCat 中不再可用。找到一個可以與 AROS 構建系統一起使用的替換。
  • 將 AROS 的所有修復程式帶回到 FlexCat 的當前主幹。透過加入 Sourceforge 上的專案或將其傳送給維護人員。

如果您願意加入團隊並將更改提交到 sourceforge.net 上的 SVN 儲存庫,我們將不勝感激。只需詢問 Jens Langer(damato#light-speed.de)將您新增到開發者列表中。

可選:等待“vendor”分支在 AROS 儲存庫中可用,並使用該分支。

/*
    Copyright © 1995-2004, The AROS Development Team. All rights reserved.
    $Id: locale.c 30794 2009-03-08 02:19:07Z neil $
*/

#include <exec/types.h>
#include <proto/locale.h>

#define CATCOMP_ARRAY
#include "strings.h"

#define CATALOG_NAME     "AiRcOS.catalog"
#define CATALOG_VERSION  0

/*** Variables **************************************************************/
struct Catalog *catalog;

/*** Functions **************************************************************/
/* Main *********************************************************************/
CONST_STRPTR _(ULONG id)
{
    if (LocaleBase != NULL && catalog != NULL)
    {
	return GetCatalogStr(catalog, id, CatCompArray[id].cca_Str);
    } 
    else 
    {
	return CatCompArray[id].cca_Str;
    }
}

/* Setup ********************************************************************/
VOID Locale_Initialize(VOID)
{
    if (LocaleBase != NULL)
    {
        catalog = OpenCatalog
        ( 
            NULL, CATALOG_NAME, OC_Version, CATALOG_VERSION, TAG_DONE 
        );
    }
    else
    {
        catalog = NULL;
    }
}

VOID Locale_Deinitialize(VOID)
{
    if(LocaleBase != NULL && catalog != NULL) CloseCatalog(catalog);
}
#ifndef _LOCALE_H_
#define _LOCALE_H_

/*
    Copyright © 2003-2004, The AROS Development Team. All rights reserved.
    $Id: locale.h 30794 2009-03-08 02:19:07Z neil $
*/

#include <exec/types.h>

#define CATCOMP_NUMBERS
#include "strings.h"

/*** Prototypes *************************************************************/
/* Main *********************************************************************/
CONST_STRPTR _(ULONG ID);       /* Get a message, as a STRPTR */
#define __(id) ((IPTR) _(id))   /* Get a message, as an IPTR */

/* Setup ********************************************************************/
VOID Locale_Initialize(VOID);
VOID Locale_Deinitialize(VOID);

#endif /* _LOCALE_H_ */

參考文獻

[編輯 | 編輯原始碼]
/* constants for GetLocaleStr() */
#define DAY_1		1	/* Sunday    */
#define DAY_2		2	/* Monday    */
#define DAY_3		3	/* Tuesday   */
#define DAY_4		4	/* Wednesday */
#define DAY_5		5	/* Thursday  */
#define DAY_6		6	/* Friday    */
#define DAY_7		7	/* Saturday  */

#define ABDAY_1	8	/* Sun */
#define ABDAY_2	9	/* Mon */
#define ABDAY_3	10	/* Tue */
#define ABDAY_4	11	/* Wed */
#define ABDAY_5	12	/* Thu */
#define ABDAY_6	13	/* Fri */
#define ABDAY_7	14	/* Sat */

#define MON_1		15	/* January   */
#define MON_2		16	/* February  */
#define MON_3		17	/* March     */
#define MON_4		18	/* April     */
#define MON_5		19	/* May	     */
#define MON_6		20	/* June      */
#define MON_7		21	/* July      */
#define MON_8		22	/* August    */
#define MON_9		23	/* September */
#define MON_10		24	/* October   */
#define MON_11		25	/* November  */
#define MON_12		26	/* December  */

#define ABMON_1	27	/* Jan */
#define ABMON_2	28	/* Feb */
#define ABMON_3	29	/* Mar */
#define ABMON_4	30	/* Apr */
#define ABMON_5	31	/* May */
#define ABMON_6	32	/* Jun */
#define ABMON_7	33	/* Jul */
#define ABMON_8	34	/* Aug */
#define ABMON_9	35	/* Sep */
#define ABMON_10	36	/* Oct */
#define ABMON_11	37	/* Nov */
#define ABMON_12	38	/* Dec */

#define YESSTR		39	/* affirmative response for yes/no queries */
#define NOSTR		40	/* negative response for yes/no queries    */

#define AM_STR		41	/* AM */
#define PM_STR		42	/* PM */

#define SOFTHYPHEN	43	/* soft hyphenation */
#define HARDHYPHEN	44	/* hard hyphenation */

#define OPENQUOTE	45	/* start of quoted block */
#define CLOSEQUOTE	46	/* end of quoted block	 */

#define YESTERDAYSTR	47	/* Yesterday */
#define TODAYSTR	48	/* Today     */
#define TOMORROWSTR	49	/* Tomorrow  */
#define FUTURESTR	50	/* Future    */

#define MAXSTRMSG	51	/* current number of defined strings */

/* This structure must only be allocated by locale.library and is READ-ONLY! */

struct Locale
{
    STRPTR  loc_LocaleName;	      /* locale's name		     */
    STRPTR  loc_LanguageName;	      /* language of this locale     */
    STRPTR  loc_PrefLanguages[10];    /* preferred languages	     */
    ULONG   loc_Flags;		      /* always 0 for now	     */

    ULONG   loc_CodeSet;	      /* always 0 for now	     */
    ULONG   loc_CountryCode;	      /* user's country code	     */
    ULONG   loc_TelephoneCode;	      /* country's telephone code    */
    LONG    loc_GMTOffset;	      /* minutes from GMT	     */
    UBYTE   loc_MeasuringSystem;      /* what measuring system?      */
    UBYTE   loc_CalendarType;	      /* what calendar type?	     */
    UBYTE   loc_Reserved0[2];

    STRPTR  loc_DateTimeFormat;       /* regular date & time format  */
    STRPTR  loc_DateFormat;	      /* date format by itself	     */
    STRPTR  loc_TimeFormat;	      /* time format by itself	     */

    STRPTR  loc_ShortDateTimeFormat;  /* short date & time format    */
    STRPTR  loc_ShortDateFormat;      /* short date format by itself */
    STRPTR  loc_ShortTimeFormat;      /* short time format by itself */

    /* for numeric values */
    STRPTR  loc_DecimalPoint;	      /* character before the decimals */
    STRPTR  loc_GroupSeparator;       /* separates groups of digits    */
    STRPTR  loc_FracGroupSeparator;   /* separates groups of digits    */
    UBYTE  *loc_Grouping;	      /* size of each group	       */
    UBYTE  *loc_FracGrouping;	      /* size of each group	       */

    /* for monetary values */
    STRPTR  loc_MonDecimalPoint;
    STRPTR  loc_MonGroupSeparator;
    STRPTR  loc_MonFracGroupSeparator;
    UBYTE  *loc_MonGrouping;
    UBYTE  *loc_MonFracGrouping;
    UBYTE   loc_MonFracDigits;	      /* digits after the decimal point   */
    UBYTE   loc_MonIntFracDigits;     /* for international representation */
    UBYTE   loc_Reserved1[2];

    /* for currency symbols */
    STRPTR  loc_MonCS;		      /* currency symbol	      */
    STRPTR  loc_MonSmallCS;	      /* symbol for small amounts     */
    STRPTR  loc_MonIntCS;	      /* international (ISO 4217) code */

    /* for positive monetary values */
    STRPTR  loc_MonPositiveSign;      /* indicate positive money value	 */
    UBYTE   loc_MonPositiveSpaceSep;  /* determine if separated by space */
    UBYTE   loc_MonPositiveSignPos;   /* position of positive sign	 */
    UBYTE   loc_MonPositiveCSPos;     /* position of currency symbol	 */
    UBYTE   loc_Reserved2;

    /* for negative monetary values */
    STRPTR  loc_MonNegativeSign;      /* indicate negative money value	 */
    UBYTE   loc_MonNegativeSpaceSep;  /* determine if separated by space */
    UBYTE   loc_MonNegativeSignPos;   /* position of negative sign	 */
    UBYTE   loc_MonNegativeCSPos;     /* position of currency symbol	 */
    UBYTE   loc_Reserved3;
};

/* constants for Locale.loc_MeasuringSystem */
#define MS_ISO		0	/* international metric system */
#define MS_AMERICAN	1	/* american system	       */
#define MS_IMPERIAL	2	/* imperial system	       */
#define MS_BRITISH	3	/* british system	       */

/* constants for Locale.loc_CalendarType */
#define CT_7SUN 0   /* 7 days a week, Sunday is the first day	 */
#define CT_7MON 1   /* 7 days a week, Monday is the first day	 */
#define CT_7TUE 2   /* 7 days a week, Tuesday is the first day	 */
#define CT_7WED 3   /* 7 days a week, Wednesday is the first day */
#define CT_7THU 4   /* 7 days a week, Thursday is the first day  */
#define CT_7FRI 5   /* 7 days a week, Friday is the first day	 */
#define CT_7SAT 6   /* 7 days a week, Saturday is the first day  */

/* constants for Locale.loc_MonPositiveSpaceSep and Locale.loc_MonNegativeSpaceSep */
#define SS_NOSPACE 0  /* cur. symbol is NOT separated from value with a space */
#define SS_SPACE   1  /* cur. symbol IS separated from value with a space     */

/* constants for Locale.loc_MonPositiveSignPos and Locale.loc_MonNegativeSignPos */
#define SP_PARENS    0	/* () surround the quantity and currency_symbol   */
#define SP_PREC_ALL  1	/* sign string comes before amount and symbol	  */
#define SP_SUCC_ALL  2	/* sign string comes after amount and symbol	  */
#define SP_PREC_CURR 3	/* sign string comes right before currency symbol */
#define SP_SUCC_CURR 4	/* sign string comes right after currency symbol  */

/* constants for Locale.loc_MonPositiveCSPos and Locale.loc_MonNegativeCSPos */
#define CSP_PRECEDES 0	/* currency symbol comes before value */
#define CSP_SUCCEEDS 1	/* currency symbol comes after value  */

/* elements of the byte arrays pointed to by:
 *   Locale.loc_Grouping
 *   Locale.loc_FracGrouping
 *   Locale.loc_MonGrouping
 *   Locale.loc_MonFracGrouping
 * are interpreted as follows:
 *
 *    255     indicates that no further grouping is to be performed
 *    0       indicates that the previous element is to be repeatedly used for the remainder of the digits
 *    <other> the number of digits that comprises the current group
 */

/* This structure must only be allocated by locale.library and is READ-ONLY! */

struct Catalog
{
    struct Node cat_Link;	/* for internal linkage    */
    UWORD	cat_Pad;	/* to longword align	   */
    STRPTR	cat_Language;	/* language of the catalog */
    ULONG	cat_CodeSet;	/* currently always 0	   */
    UWORD	cat_Version;	/* version of the catalog  */
    UWORD	cat_Revision;	/* revision of the catalog */
};
void CloseCatalog(struct Catalog *catalog) (A0)
void CloseLocale(struct Locale *locale) (A0)

ULONG ConvToLower(const struct Locale *locale, ULONG character) (A0, D0)
ULONG ConvToUpper(const struct Locale *locale, ULONG character) (A0, D0)

void FormatDate(const struct Locale *locale, CONST_STRPTR formatString, const struct DateStamp *date, const struct Hook *hook) (A0, A1, A2, A3)

APTR FormatString(const struct Locale *locale, CONST_STRPTR fmtTemplate, CONST_APTR dataStream, const struct Hook *putCharFunc) (A0, A1, A2, A3)

CONST_STRPTR GetCatalogStr(const struct Catalog *catalog, ULONG stringNum, CONST_STRPTR defaultString) (A0, D0, A1)
CONST_STRPTR GetLocaleStr(const struct Locale *locale, ULONG stringNum) (A0, D0)

ULONG IsAlNum(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsAlpha(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsCntrl(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsDigit(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsGraph(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsLower(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsPrint(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsPunct(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsSpace(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsUpper(const struct Locale *locale, ULONG character) (A0, D0)
ULONG IsXDigit(const struct Locale *locale, ULONG character) (A0, D0)

struct Catalog *OpenCatalogA(const struct Locale *locale, CONST_STRPTR name, const struct TagItem *tags) (A0, A1, A2)

struct Locale *OpenLocale(CONST_STRPTR name) (A0)

BOOL ParseDate(struct Locale *locale, struct DateStamp *date, CONST_STRPTR fmtTemplate, struct Hook *getCharFunc) (A0, A1, A2, A3)
struct Locale *LocalePrefsUpdate(struct Locale *locale) (A0)

ULONG StrConvert(const struct Locale *locale, CONST_STRPTR string, APTR buffer, ULONG bufferSize, ULONG type) (A0, A1, A2, D0, D1)
LONG StrnCmp(const struct Locale *locale, CONST_STRPTR string1, CONST_STRPTR string2, LONG length, ULONG type) (A0, A1, A2, D0, D1)

private
APTR LocRawDoFmt(CONST_STRPTR FormatString, APTR DataStream, VOID_FUNC PutChProc, APTR PutChData) (A0, A1, A2, A3)
LONG LocStrnicmp(CONST_STRPTR string1, CONST_STRPTR string2, LONG length) (A0, A1, D0)
LONG LocStricmp(CONST_STRPTR string1, CONST_STRPTR string2) (A0, A1)
ULONG LocToLower(ULONG character) (D0)
ULONG LocToUpper(ULONG character) (D0)
LONG LocDateToStr(struct DateTime *datetime) (D1)
LONG LocStrToDate(struct DateTime *datetime) (D1)
CONST_STRPTR LocDosGetLocalizedString(LONG stringNum) (D1)
華夏公益教科書