ヘッダーをスキップ
Oracle® Application Express APIリファレンス
リリース4.2 for Oracle Database 12c
B71340-03
  目次へ移動
目次
索引へ移動
索引

前
 
次
 

14 APEX_LANG

APEX_LANG APIを使用してメッセージを翻訳できます。

トピック:

CREATE_LANGUAGE_MAPPINGプロシージャ

このプロシージャを使用して、アプリケーションの翻訳の言語マッピングを作成します。翻訳されたアプリケーションは新しいアプリケーションとして公開されますが、アプリケーション・ビルダーで直接編集することはできません。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.CREATE_LANGUAGE_MAPPING (
  p_application_id IN NUMBER,
  p_language IN VARCHAR2,
  p_translation_application_id IN NUMBER )

パラメータ

表14-1 CREATE_LANGUAGE_MAPPINGパラメータ

パラメータ 説明

p_application_id

言語マッピングを作成するアプリケーションのID。これはプライマリ言語アプリケーションのIDです。

p_language

マッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。

p_translation_application_id

基礎となる翻訳済アプリケーションのIDの一意の整数。この数字は0で終了することはできません。


次の例に、既存のApplication Expressアプリケーションの言語マッピングの作成方法を示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;

    -- Now, actually create the language mapping
    apex_lang.create_language_mapping(
        p_application_id => 63969,
        p_language => 'ja',
        p_translation_application_id => 778899 );
    commit;
    --
    -- Print what we just created to confirm
    --
    for c1 in (select *
                 from apex_application_trans_map
                where primary_application_id = 63969) loop
        dbms_output.put_line( 'translated_application_id: ' || c1.translated_application_id );
        dbms_output.put_line( 'translated_app_language: ' || c1.translated_app_language );
    end loop;
end;
/

DELETE_LANGUAGE_MAPPINGプロシージャ

このプロシージャを使用して、アプリケーションの翻訳の言語マッピングを削除します。このプロシージャは指定した言語およびマッピングの翻訳リポジトリ内のすべての翻訳済文字列を削除します。翻訳されたアプリケーションは新しいアプリケーションとして公開されますが、アプリケーション・ビルダーで直接編集することはできません。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.DELETE_LANGUAGE_MAPPING (
  p_application_id IN NUMBER,
  p_language IN VARCHAR2 )

パラメータ

表14-2 DELETE_LANGUAGE_MAPPINGパラメータ

パラメータ 説明

p_application_id

言語マッピングを削除するアプリケーションのID。これはプライマリ言語アプリケーションのIDです。

p_language

既存のマッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。


次の例に、既存のApplication Expressアプリケーションの言語マッピングおよび既存の翻訳マッピングの削除方法を示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
     end loop;
    -- Now, delete the language mapping
    apex_lang.delete_language_mapping(
        p_application_id => 63969,
        p_language => 'ja' );
    commit;
    --
    -- Print what we just updated to confirm
    --
    for c1 in (select count(*) thecount
                 from apex_application_trans_map
                where primary_application_id = 63969) loop
        dbms_output.put_line( 'Translation mappings found: ' || c1.thecount );
    end loop;
end;
/

LANGファンクション

このファンクションは、動的翻訳で定義された翻訳に対して翻訳済テキスト文字列を戻します。

構文

APEX_LANG.LANG (
    p_primary_text_string IN VARCHAR2 DEFAULT NULL,
    p0 IN VARCHAR2 DEFAULT NULL,
    p1 IN VARCHAR2 DEFAULT NULL,
    p2 IN VARCHAR2 DEFAULT NULL,
    ...
    p9 IN VARCHAR2 DEFAULT NULL,
    p_primary_language IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;

パラメータ

表14-3に、APEX_LANG.LANGファンクションで使用可能なパラメータを示します。

表14-3 LANGパラメータ

パラメータ 説明

p_primary_text_string

プライマリ言語のテキスト文字列。これは、「動的翻訳」の「翻訳元テキスト」の値になります。

p0からp9

動的置換値: p0は翻訳文字列の%0に、p1は翻訳文字列の%1に、p2は翻訳文字列の%2に対応します(以降同様)。

p_primary_language

取得されるメッセージの言語コード。指定しない場合、Oracle Application Expressは、アプリケーション言語の派生元属性で定義されているとおり、ユーザーの現行の言語を使用します。

参照: 『Oracle Application Expressアプリケーション・ビルダー・ユーザーズ・ガイド』の「アプリケーションへのプライマリ言語の指定」


すべての1次色を定義する表があるとします。それぞれの色に動的メッセージを定義し、問合せで定義された値にLANGファンクションを適用します。次に例を示します。

SELECT APEX_LANG.LANG(color)
FROM my_colors

アプリケーションをドイツ語で実行中の場合、my_colors表の「カラー」列の値がREDであったとすると、赤にドイツ語を定義すると、前述の例では、ROTが戻されます。

MESSAGEファンクション

このファンクションは、PL/SQLのストアド・プロシージャ、ストアド・ファンクション、ストアド・トリガー、パッケージ化されたプロシージャおよびパッケージ化されたファンクションから生成されたテキスト文字列(メッセージ)の翻訳に使用します。

構文

APEX_LANG.MESSAGE (
    p_name IN VARCHAR2 DEFAULT NULL,
    p0 IN VARCHAR2 DEFAULT NULL,
    p1 IN VARCHAR2 DEFAULT NULL,
    p2 IN VARCHAR2 DEFAULT NULL,
    ...
    p9 IN VARCHAR2 DEFAULT NULL,
    p_lang IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;

パラメータ

表14-4に、APEX_LANG.MESSAGEファンクションで使用可能なパラメータを示します。

表14-4 MESSAGEパラメータ

パラメータ 説明

p_name

Oracle Application Expressでアプリケーションの「共有コンポーネント」の下にある「テキスト・メッセージ」で定義されたメッセージの名前。

p0からp9

動的置換値: p0は翻訳文字列の%0に、p1は翻訳文字列の%1に、p2は翻訳文字列の%2に対応します(以降同様)。

p_lang

取得されるメッセージの言語コード。指定しない場合、Oracle Application Expressは、アプリケーション言語の派生元属性で定義されているとおり、ユーザーの現行の言語を使用します。

参照: 『Oracle Application Expressアプリケーション・ビルダー・ユーザーズ・ガイド』の「アプリケーションへのプライマリ言語の指定」


次の例では、アプリケーションのGREETING_MSGというメッセージを、英語で「Good morning%0」、ドイツ語で「Guten Tag%1」と定義したと仮定しています。この例は、PL/SQLからこのメッセージを呼び出す方法を示しています。

BEGIN
--
-- Print the greeting
--
HTP.P(APEX_LANG.MESSAGE('GREETING_MSG', V('APP_USER')));
END;

p_lang属性の定義は、Application Expressエンジンがアプリケーションのプライマリ言語を導出する方法によって異なります。たとえば、アプリケーションをドイツ語で実行中で、前回のコールがAPEX_LANG.MESSAGE APIに対して行われた場合、Application Expressエンジンは、最初にLANG_CODEdeであるGREETING_MSGというメッセージを検索します。見つからない場合は、アプリケーションのプライマリ言語属性に戻ります。それでも見つからない場合、Application Expressエンジンは、言語コードがenであるこの名前のメッセージを検索します。


参照:

『Oracle Application Expressアプリケーション・ビルダー・ユーザーズ・ガイド』の「アプリケーションへのプライマリ言語の指定」

PUBLISH_APPLICATIONプロシージャ

このプロシージャを使用して、アプリケーションの翻訳バージョンを公開します。このプロシージャは基礎となる、プライマリ・アプリケーションの非表示のレプリカを作成し、この新しいアプリケーションの翻訳リポジトリからの文字列をマージします。アプリケーションの翻訳バージョンを更新するたびに、シードおよび公開プロセスを実行し、プライマリ・アプリケーションと同期させます。

このアプリケーションはアプリケーション・ビルダーでは表示できません。公開およびエクスポートはできますが、直接編集することはできません。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.PUBLISH_APPLICATION (
  p_application_id IN NUMBER,
  p_language IN VARCHAR2 )

パラメータ

表14-5 PUBLISH_APPLICATIONパラメータ

パラメータ 説明

p_application_id

翻訳バージョンを公開および作成するアプリケーションのID。これはプライマリ言語アプリケーションのIDです。

p_language

既存の翻訳マッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。


次の例に、Application Expressアプリケーションおよび言語の公開プロセスを示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;
    -- Now, publish the translated version of the application
    apex_lang.publish_application(
        p_application_id => 63969,
        p_language => 'ja' );
    commit;
end;
/

SEED_TRANSLATIONSプロシージャ

このプロシージャを使用して、指定したアプリケーションおよび言語の翻訳リポジトリをシードします。このプロシージャは、新しい、更新済および削除済翻訳可能文字列のすべての含む翻訳リポジトリをアプリケーションから移入します。アプリケーションの翻訳バージョンを更新するたびに、シードおよび公開プロセスを実行し、プライマリ・アプリケーションと同期させます。

構文

APEX_LANG.SEED_TRANSLATIONS (
  p_application_id IN NUMBER,
  p_language IN VARCHAR2 )

パラメータ

表14-6 SEED_TRANSLATIONSパラメータ

パラメータ 説明

p_application_id

翻訳リポジトリを更新するアプリケーションのID。これはプライマリ言語アプリケーションのIDです。

p_language

既存の翻訳マッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。


次の例に、Application Expressアプリケーションおよび言語の翻訳リポジトリのシード・プロセスを示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;
    -- Now, seed the translation repository
    apex_lang.seed_translations(
        p_application_id => 63969,
        p_language => 'ja' );
    commit;
    -- Print out the total number of potentially translatable strings
    --
    for c1 in (select count(*) thecount
                 from apex_application_trans_repos
                where application_id = 63969) loop
        dbms_output.put_line( 'Potentially translatable strings found: ' || c1.thecount );
    end loop;
end;
/

UPDATE_LANGUAGE_MAPPINGプロシージャ

このプロシージャを使用して、アプリケーションの翻訳の言語マッピングを更新します。翻訳されたアプリケーションは新しいアプリケーションとして公開されますが、アプリケーション・ビルダーで直接編集することはできません。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.UPDATE_LANGUAGE_MAPPING (
  p_application_id IN NUMBER,
  p_language IN VARCHAR2,
  p_new_trans_application_id IN NUMBER )

パラメータ

表14-7 UPDATE_LANGUAGE_MAPPINGパラメータ

パラメータ 説明

p_application_id

言語マッピングを更新するアプリケーションのID。これはプライマリ言語アプリケーションのIDです。

p_language

既存のマッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。このマッピングの言語はこのプロシージャでは更新できません。新しい翻訳アプリケーションIDのみです。

p_new_trans_application_id

基礎となる翻訳済アプリケーションIDの新しい一意の整数。この数字は0で終了することはできません。


次の例に、既存のApplication Expressアプリケーションの言語マッピングおよび既存の翻訳マッピングの更新方法を示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;
    -- Now, update the language mapping
    apex_lang.update_language_mapping(
        p_application_id => 63969,
        p_language => 'ja',
        p_new_trans_application_id => 881188 );
    commit;
    --
    -- Print what we just updated to confirm
    --
    for c1 in (select *
                 from apex_application_trans_map
                where primary_application_id = 63969) loop
        dbms_output.put_line( 'translated_application_id: ' || c1.translated_application_id );
        dbms_output.put_line( 'translated_app_language: ' || c1.translated_app_language );
    end loop;
end;
/

UPDATE_MESSAGEプロシージャ

このプロシージャを使用して、指定したアプリケーションの翻訳可能テキスト・メッセージを更新します。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.UPDATE_MESSAGE (
  p_id IN NUMBER,
  p_message_text IN VARCHAR2 )

パラメータ

表14-8 UPDATE_MESSAGEパラメータ

パラメータ 説明

p_id

テキスト・メッセージのID。

p_message_text

翻訳可能テキスト・メッセージの新しいテキスト。


次の例に、既存の翻訳可能テキスト・メッセージの更新方法を示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;
    -- Locate the ID of the specific message and update it with the new text
    for c1 in (select translation_entry_id
                 from apex_application_translations
                where application_id = 63969
                  and translatable_message = 'TOTAL_COST'
                  and language_code = 'ja') loop
        apex_lang.update_message(
            p_id => c1.translation_entry_id,
            p_message_text => 'The total cost is: %0');
        commit;
        exit;
    end loop;
end;
/

UPDATE_TRANSLATED_STRINGプロシージャ

このプロシージャを使用して、シードされた翻訳リポジトリの翻訳文字列を更新します。


注意:

このプロシージャはApplication Expressリリース4.2.3以降で使用できます。

構文

APEX_LANG.UPDATE_TRANSLATED_STRING (
  p_id IN NUMBER,
  p_language IN VARCHAR2
  p_string IN VARCHAR2 )

パラメータ

表14-9 UPDATE_TRANSLATED_STRINGパラメータ

パラメータ 説明

p_id

翻訳リポジトリ内の文字列のID。

p_language

既存の翻訳マッピング用のIANA言語コード。たとえば、en-us、fr-ca、ja、heがあります。このマッピングの言語はこのプロシージャでは更新できません。新しい翻訳アプリケーションIDのみです。

p_string

翻訳リポジトリ内の文字列の新しい値。


次の例に、翻訳リポジトリ内の既存の文字列の更新方法を示します。

begin
    --
    -- If running from SQL*Plus, we need to set the environment
    -- for the Application Express workspace associated with this schema. The
    -- call to apex_util.set_security_group_id is not necessary if
    -- you're running within the context of the Application Builder
    -- or an Application Express application.
    --
    for c1 in (select workspace_id
                 from apex_workspaces) loop
        apex_util.set_security_group_id( c1.workspace_id );
        exit;
    end loop;
    -- Locate all strings in the repository for the specified application
    -- which are 'Search' and change to 'Find'
    for c1 in (select id
                 from apex_application_trans_repos
                where application_id = 63969
                  and dbms_lob.compare(from_string, to_nclob('Search')) = 0
                  and language_code = 'ja') loop
        apex_lang.update_translated_string(
            p_id => c1.id,
            p_language => 'ja',
            p_string => 'Find');
        commit;
        exit;
    end loop;
end;
/