メインコンテンツまでスキップ

WOVN Ignore 機能

WOVN Flutter SDKは、特定のテキストを翻訳から除外するための柔軟なオプションを提供します。これは以下の場合に便利です。

  • 機密情報の保護(パスワード、APIキー、個人データなど)
  • 技術的な識別子の除外(エラーコード、IDなど)
  • 特定のUI要素での原文の維持

方法1:isIgnoredプロパティの使用

任意のWovnTextまたはWovnRichTextウィジェットにisIgnored: trueを追加することで、翻訳を防止できます。

基本的なTextの例

import 'package:wovn_flutter/wovn_flutter.dart';

typedef Text = WovnText;

Text(
'このテキストは翻訳されません',
isIgnored: true,
style: TextStyle(color: Colors.red),
)

Text.richの例

Text.rich(
TextSpan(
text: 'このText.richは',
children: [
TextSpan(
text: 'WOVNによって無視されます。',
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(
text: 'すべてのコンテンツが原文のまま残ります。',
style: TextStyle(fontStyle: FontStyle.italic),
),
],
),
isIgnored: true,
)

RichTextの例

import 'package:wovn_flutter/wovn_flutter.dart';

typedef RichText = WovnRichText;

RichText(
text: TextSpan(
text: 'このRichTextは',
style: TextStyle(color: Colors.black),
children: [
TextSpan(
text: '翻訳されず、',
style: TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(
text: '原文のまま残ります。',
style: TextStyle(fontStyle: FontStyle.italic),
),
],
),
isIgnored: true,
)

方法2:キーベースの除外

"WovnIgnore"という文字列を含むキーを持つウィジェットは、自動的に翻訳から除外されます(大文字小文字を区別します)。

キーベースのTextの例

Text(
'このテキストはキーによって無視されます',
key: Key('WovnIgnore_UserPassword'),
style: TextStyle(color: Colors.red),
)

キーベースのText.richの例

Text.rich(
TextSpan(
text: 'このコンテンツは',
children: [
TextSpan(
text: 'キーのために無視されます。',
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
key: Key('WovnIgnore_SensitiveData'),
)

キーベースのRichTextの例

RichText(
text: TextSpan(
text: 'APIキー: ',
children: [
TextSpan(
text: 'sk_live_1234567890abcdef',
style: TextStyle(fontFamily: 'monospace'),
),
],
),
key: Key('WovnIgnore_ApiKey_Display'),
)

キーの命名規則

キーには"WovnIgnore"という文字列が含まれている必要があります(大文字小文字を区別します)。一般的なパターンは以下の通りです。

  • Key('WovnIgnore_FieldName') - 標準形式
  • Key('Wovnignore_Text_Widget1') - 代替形式
  • Key('UserForm_WovnIgnore_Password') - 長いキー名に埋め込む
  • Key('WovnIgnore123') - 数字のサフィックス付き
ベストプラクティス

テキストが無視される理由を示す分かりやすいキー名を使用してください。

  • Key('WovnIgnore_Password_Field')
  • Key('WovnIgnore_API_Token')
  • Key('WovnIgnore_Brand_Logo_Text')

方法の比較

方法使用するケース利点
isIgnored: trueウィジェットレベルで明示的に制御したい場合コード内で意図が明確、見つけやすい、あらゆるウィジェット構造で機能
キーベースプログラム的にウィジェットを管理する場合や、類似要素を一括で無視する場合動的ウィジェットに便利、キー生成ロジックで適用可能

完全な例

import 'package:flutter/material.dart';
import 'package:wovn_flutter/wovn_flutter.dart';

typedef Text = WovnText;
typedef RichText = WovnRichText;

class UserProfileScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('ユーザープロフィール')),
body: ListView(
children: [
// このテキストは翻訳されます
Text('プロフィールへようこそ'),

Divider(),

// 方法1:isIgnoredプロパティを使用
Text(
'ユーザーID: ABC123XYZ',
isIgnored: true,
style: TextStyle(fontFamily: 'monospace'),
),

Divider(),

// 方法2:キーベースの除外を使用
Text(
'APIトークン: sk_live_xxxxxxxxxxxx',
key: Key('WovnIgnore_APIToken'),
style: TextStyle(fontFamily: 'monospace'),
),

Divider(),

// このテキストは翻訳されます
Text('アカウント設定'),

Divider(),

// 複雑な例:isIgnored付きのRichText
RichText(
text: TextSpan(
text: 'パスワード: ',
style: TextStyle(color: Colors.black),
children: [
TextSpan(
text: '••••••••',
style: TextStyle(fontSize: 20),
),
],
),
isIgnored: true,
),
],
),
);
}
}

除外されたテキストの確認

テキストが適切に除外されていることを確認するには:

  1. 開発モードガイドに従って開発モードを有効化する
  2. 以下のコードで異なる言語設定でアプリを実行する:
    Wovn().changeLangUsingLocaleString('ja');
    Wovn().changeLangUsingLocaleString('en');
  3. 除外されたテキストが原文のまま残り、他のテキストが翻訳されることを確認する
  4. WOVNダッシュボードで、除外されたテキストが翻訳のために報告されていないことを確認する

関連ドキュメント