Changes between Version 3 and Version 4 of TracInterfaceCustomization


Ignore:
Timestamp:
Dec 30, 2016, 2:54:47 AM (7 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracInterfaceCustomization

    v3 v4  
    1 = Trac のインタフェースをカスタマイズする = #CustomizingtheTracInterface
     1= Customizing the Trac Interface
    22[[TracGuideToc]]
    3 [[PageOutline]]
     3[[PageOutline(2-5,Contents,pullout)]]
    44
    5 == イントロダクション == #Introduction
    6 このページは Trac の外観をカスタマイズする方法をユーザに提案するために書きました。主要な話題は HTML テンプレートと CSS ファイルであり、プログラムコードではありません。ユーザ自身の特定のニーズを満たすために Trac の外観を変更する方法を、ユーザに示すことを意図しています。 Trac の全てのユーザにとって有益な、インタフェース変更の提案は、このページに書くのではなくチケットを使用してください。 [[BR]] '''(訳注: 本家サイトのチケットの話です)'''
     5This page gives suggestions on how to customize the look of Trac. Topics include editing the HTML templates and CSS files, but not the program code itself. The topics show users how they can modify the look of Trac to meet their specific needs. Suggestions for changes to Trac's interface applicable to all users should be filed as tickets, not listed on this page.
    76
    8 == プロジェクトのロゴとアイコン == #ProjectLogoandIcon
    9 Trac のインタフェースをカスタマイズする中で、最も簡単なのは、ロゴとサイトアイコンです。両方とも [wiki:TracIni trac.ini] に設定するだけで構成できます。
     7== Project Logo and Icon
     8The easiest parts of the Trac interface to customize are the logo and the site icon. Both of these can be configured with settings in [wiki:TracIni trac.ini].
    109
    11 ロゴやアイコンのイメージは、 Trac Environment フォルダの中の "htdocs" というフォルダに置かなければいけません。 (''Note: バージョン 0.9 以前の Trac で作成したプロジェクトでは、このフォルダを自分で作成する必要があります'')
     10The logo or icon image should be put in a folder named "htdocs" in your project's environment folder. ''Note: in projects created with a Trac version prior to 0.9 you will need to create this folder''.
    1211
    13  ''Note: 実際は、ロゴとアイコンはサーバのどこのパスにおいてもかまいません(Web サーバがアクセスできるところならですが)。設定の中でそれらの絶対またはサーバの相対 URL を使用します。''
     12'''Note''': you can actually put the logo and icon anywhere on your server (as long as it's accessible through the web server), and use their absolute or server-relative URLs in the configuration.
    1413
    15 [wiki:TracIni trac.ini] の適切なセクションの構成は以下の通りです:
     14Now configure the appropriate section of your [wiki:TracIni trac.ini]:
    1615
    17 === ロゴ === #Logo
    18 `src` の設定を `site/` に続く画像ファイルの名前に変更してください。 `width` と `height` は画像ファイルにあわせて設定を変更してください。(Trac の chrome ハンドラはプロジェクトのディレクトリ `htdocs` の中のファイル用に "`site/`" を使用し、Trac インストール時に作成された共通のディレクトリ `htdocs` 用に "`common/`" を使用します。) Note: 'site/' はプロジェクト名の代わりに使っているのではなく、文字通り使用されるべき実際のプレフィクスです。例えば、プロジェクトに 'sandbox' という名前を付け、イメージファイルが 'red_logo.gif' である場合、 'src' には 'sandbox/red_logo.gif' ではなく、 'site/red_logo.gif' を設定します。
     16=== Logo
     17Change the `src` setting to `site/` followed by the name of your image file. The `width` and `height` settings should be modified to match your image's dimensions. The Trac chrome handler uses `site/` for files within the project directory `htdocs`, and `common/` for the common `htdocs` directory belonging to a Trac installation. Note that 'site/' is not a placeholder for your project name, it is the literal prefix that should be used. For example, if your project is named 'sandbox', and the image file is 'red_logo.gif' then the 'src' setting would be 'site/red_logo.gif', not 'sandbox/red_logo.gif'.
    1918
    20 {{{
     19{{{#!ini
    2120[header_logo]
    2221src = site/my_logo.gif
     
    2625}}}
    2726
    28 === アイコン === #Icon
    29 アイコンは `.gif` か `.ico` 形式の 32x32 の画像である必要があります。 `icon` の設定を `site/` に続くアイコンファイルの名前に変更してください。アイコンは通常、サイトの URL の横や、 `ブックマーク` メニューに表示されます。
     27=== Icon
     28Icons are small images displayed by your web browser next to the site's URL and in the `Bookmarks` menu. Icons should be a 32x32 image in `.gif` or `.ico` format. Change the `icon` setting to `site/` followed by the name of your icon file:
    3029
    31 {{{
     30{{{#!ini
    3231[project]
    3332icon = site/my_icon.ico
    3433}}}
    3534
    36 Note: Internet Explorer では、ホストのルートディレクトリにある ``favicon.ico`` という名前のファイルしか許容しないため、このアイコンは無視されます。プロジェクトアイコンを IE と他のブラウザで共用したい場合、アイコンをホストのドキュメントルートに配置し、 ``trac.ini`` から以下のように参照します:
     35== Custom Navigation Entries
     36The new [mainnav] and [metanav] can now be used to customize the text and link used for the navigation items, or even to disable them, but not for adding new ones.
    3737
    38 {{{
    39 [project]
    40 icon = /favicon.ico
    41 }}}
    42 
    43 ブラウザのアドレスバーでのアイコン表示に問題がある場合、アイコンのファイル拡張子の後に "?" (クエスチョンマーク) を置くと回避できることがあります。
    44 
    45 {{{
    46 [project]
    47 icon = /favicon.ico?
    48 }}}
    49 
    50 == ナビゲーション項目のカスタマイズ == #CustomNavigationEntries
    51 [mainnav] と [metanav] を使用すると、ナビゲーション項目に使用されるテキストとリンクをカスタマイズしたり、無効化することができます (新規項目を追加することはできません)。
    52 
    53 以下の例では、 Wiki のスタートページへのリンク名を "Home" に変更して、 "!Help/Guide" を非表示にします。さらに、 "View Tickets" エントリを特定のレポートにリンクさせます。
    54 {{{
     38In the following example, we rename the link to the Wiki start "Home", and hide the "!Help/Guide". We also make the "View Tickets" entry link to a specific report:
     39{{{#!ini
    5540[mainnav]
    5641wiki.label = Home
     
    6146}}}
    6247
    63 mainnav と metanav についての、より詳細な記述は TracNavigation を参照してください。
     48See also TracNavigation for a more detailed explanation of the mainnav and metanav terms.
    6449
    65 == サイトの外観 == #SiteAppearance
     50== Site Appearance #SiteAppearance
    6651
    67 Trac はテンプレートエンジンに [http://genshi.edgewall.org Genshi] を使用しています。ドキュメントはまだ書かれていませんが、次の tip は動くはずです。
     52Trac is using [http://genshi.edgewall.org Genshi] as the templating engine. Say you want to add a link to a custom stylesheet, and then your own header and footer. Save the following content as `site.html` inside your projects `templates/` directory (each Trac project can have their own `site.html`), eg `/path/to/env/templates/site.html`:
    6853
    69 カスタムスタイルシートへのリンクや、独自のヘッダやフッタを追加したい場合、
    70 以下のようなの内容ファイルを、プロジェクトの `templates/` ディレクトリに `site.html` という名前で作成してください (各 Trac プロジェクトは独自の内容の `site.html` を持つことができます)。{{{/path/to/env/templates/site.html}}} の例:
    71 
    72 {{{
    73 #!xml
     54{{{#!xml
    7455<html xmlns="http://www.w3.org/1999/xhtml"
    7556      xmlns:py="http://genshi.edgewall.org/"
     
    7960  <head py:match="head" py:attrs="select('@*')">
    8061    ${select('*|comment()|text()')}
    81     <link rel="stylesheet" type="text/css"
    82           href="${href.chrome('site/style.css')}" />
     62    <link rel="stylesheet" href="${href.chrome('site/style.css')}" />
    8363  </head>
    8464
     
    9979}}}
    10080
    101 XSLT に慣れ親しんだ人であれば、 Genshi テンプレートには類似点があるのに気付くかもしれません。しかしながら Trac 固有の機能もあります。例えば `${href.chrome('site/style.css')}` は Environment に含まれる `htdocs/` にある CSS ファイルへの参照の属性に置き換えられます。 同様に、 `${chrome.htdocs_location}` は Trac インストール時に作成された共通の `htdocs/` ディレクトリを指定するために使用します。しかし [[TracIni#trac-config|[trac] htdocs_location]] のコンフィグを設定することで、ディレクトリ位置を指定しなおすことができます。
     81Notice that XSLT bears some similarities with Genshi templates. However, there are some Trac specific features, for example the `${href.chrome('site/style.css')}` attribute references `style.css` in the environment's `htdocs/` directory. In a similar fashion `${chrome.htdocs_location}` is used to specify the common `htdocs/` directory belonging to a Trac installation. That latter location can however be overriden using the [[TracIni#trac-section|[trac] htdocs_location]] configuration setting.
    10282
    103 `site.html` はサイト固有のすべての変更を含んでいる一つのファイルです。通常は、特定のセクション上で `py:match` を要素 (element) または属性 (attribute) として使用することで、カスタマイズしようとしているページを
    104 思い通りにレンダリングすることができます。
    105 [http://groups.google.com/group/trac-users/browse_thread/thread/70487fb2c406c937/ メーリングリスト] には上記の例の `site.html` について解説されていますので、参照してください。
    106 `site.html` には変更を行うための `py:match` セクションをいくつでも記載することができます。これらはすべて Genshi の文法に沿って行います。[http://genshi.edgewall.org/wiki/Documentation/xml-templates.htmlドキュメントや詳細なシンタックス] を参考にしてください。
     83`site.html` is one file to contain all your modifications. It usually works using the `py:match` directive (element or attribute), and it allows you to modify the page as it renders. The matches hook onto specific sections depending on what it tries to find and modify them.
     84See [http://groups.google.com/group/trac-users/browse_thread/thread/70487fb2c406c937/ this thread] for a detailed explanation of the above example `site.html`.
     85A `site.html` can contain any number of such `py:match` sections for whatever you need to modify. This is all Genshi, so the [http://genshi.edgewall.org/wiki/Documentation/xml-templates.html docs on the exact syntax] can be found there.
    10786
    108 
    109 チケット登録のフォームに導入テキストを表示する (プレビューが非表示のとき) 場合は、次の例を追加してください:
     87Example snippet of adding introduction text to the new ticket form (but not shown during preview):
    11088
    11189{{{#!xml
    11290<form py:match="div[@id='content' and @class='ticket']/form" py:attrs="select('@*')">
    113   <py:if test="req.environ['PATH_INFO'] == '/newticket' and (not 'preview' in req.args)">
     91  <py:if test="req.path_info == '/newticket' and (not 'preview' in req.args)">
    11492    <p>Please make sure to search for existing tickets before reporting a new one!</p>
    11593  </py:if>
    116   ${select('*')}
     94  ${select('*')} 
    11795</form>
    11896}}}
    11997
    120 この例では `req.environ['PATH_INFO']` を使用して、特定のビューだけで変更が行われるようにスコープを限定しています。例えば `site.html` でタイムラインだけで変更を行い、他のセクションには影響を及ぼしたくない場合は、 `req.environ['PATH_INFO'] == '/timelime'` を `<py:if>` の test 属性に記載します。
     98This example illustrates a technique of using `req.path_info` to limit scope of changes to one view only. For instance, to make changes in `site.html` only for timeline and avoid modifying other sections - use `req.path_info == '/timeline'` condition in `<py:if>` test.
    12199
    122 より多くの `site.html` の例が [trac:CookBook/SiteHtml CookBook/SiteHtml] で見ることができます。
     100More examples snippets for `site.html` can be found at [trac:wiki:CookBook/SiteHtml CookBook/SiteHtml].
    123101
    124 `style.css` の例は [trac:CookBook/SiteStyleCss CookBook/SiteStyleCss] で見ることができます。
     102Example snippets for `style.css` can be found at [trac:wiki:CookBook/SiteStyleCss CookBook/SiteStyleCss].
    125103
    126 0.10 からアップグレードされた Environment で、かつ `site_newticket.cs` ファイルが既に存在している場合は、ワークアラウンドすることによってテンプレートをロードすることができます - !ClearSilver の処理が含まれていない場合に限ります (訳注: `<?cs?>` が含まれていない場合) 。また、この場合はただ一つの要素 (element) だけがインポートされるので、コンテンツはある種のラッパー (`<div>` ブロックやそれに似た親コンテナ) を必要とします。インクルードするためには XInclude の名前空間を指定しなければなりませんが、ドキュメントルート以外にも置くことができます:
    127 {{{
    128 #!xml
    129 <form py:match="div[@id='content' and @class='ticket']/form" py:attrs="select('@*')"
    130         xmlns:xi="http://www.w3.org/2001/XInclude">
    131   <py:if test="req.environ['PATH_INFO'] == '/newticket' and (not 'preview' in req.args)">
    132     <xi:include href="site_newticket.cs"><xi:fallback /></xi:include>
    133   </py:if>
    134   ${select('*')}
    135 </form>
    136 }}}
     104Note that the `site.html`, despite its name, can be put in a shared templates directory, see the [[TracIni#inherit-section|[inherit] templates_dir]] option. This could provide easier maintainence as one new global `site.html` file can be made to include any existing header, footer and newticket snippets.
    137105
    138 また、共通のテンプレートディレクトリに、 `site.html` (その名前にも関わらず) を置くことができます - [[TracIni#inherit-section|[inherit] templates_dir]] オプションを参照してください。新しく、一個のグローバルな `site.html` ファイルに、ヘッダ, フッタ, チケット作成時の tips を組み込むことで、簡単なメンテナンス (および、大きなインストールを行った 0.10 からのバージョンアップのための移行パス) を提供しています。
     106== Project List #ProjectList
    139107
    140 == プロジェクトリスト == #ProjectList
     108You can use a custom Genshi template to display the list of projects if you are using Trac with multiple projects.
    141109
    142 複数の Trac プロジェクトを動かしているときに、カスタマイズした Genshi テンプレートを使用して、プロジェクトの一覧を表示することができます。
     110The following is the basic template used by Trac to display a list of links to the projects. For projects that could not be loaded, it displays an error message. You can use this as a starting point for your own index template:
    143111
    144 以下に示すのは Trac が使用している、ホストするプロジェクトへのリンクのリストを表示するための基本のテンプレートです。ロードできないプロジェクトについては、エラーメッセージを表示します。これをあなた自身のインデックステンプレートのスタートポイントとして使用することができます。
    145 
    146 {{{
    147 #!text/html
     112{{{#!text/html
    148113<!DOCTYPE html
    149114    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     
    153118      xmlns:xi="http://www.w3.org/2001/XInclude">
    154119  <head>
    155     <title>プロジェクト一覧</title>
     120    <title>Available Projects</title>
    156121  </head>
    157122  <body>
    158     <h1>プロジェクト一覧</h1>
     123    <h1>Available Projects</h1>
    159124    <ul>
    160125      <li py:for="project in projects" py:choose="">
     
    162127           title="$project.description">$project.name</a>
    163128        <py:otherwise>
    164           <small>$project.name: <em>エラー</em> <br /> ($project.description)</small>
     129          <small>$project.name: <em>Error</em> <br /> ($project.description)</small>
    165130        </py:otherwise>
    166131      </li>
     
    170135}}}
    171136
    172 カスタムテンプレートを使用する場合、 Web サーバにテンプレートのロケーションの設定を読み込ませる必要があります (確かめてみてください ... まだ 0.11 向けに変更していません):
     137Once you've created your custom template you will need to configure the webserver to tell Trac where the template is located:
    173138
    174 [wiki:TracModWSGI mod_wsgi] 用:
    175 {{{
    176 os.environ['TRAC_ENV_INDEX_TEMPLATE'] = '/path/to/template'
     139For [wiki:TracModWSGI mod_wsgi]:
     140{{{#!python
     141os.environ['TRAC_ENV_INDEX_TEMPLATE'] = '/path/to/template.html'
    177142}}}
    178143
    179 [wiki:TracFastCgi FastCGI] 用:
    180 {{{
     144For [wiki:TracFastCgi FastCGI]:
     145{{{#!apache
    181146FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects \
    182147              -initial-env TRAC_ENV_INDEX_TEMPLATE=/path/to/template
    183148}}}
    184149
    185 [wiki:TracModPython mod_python] 用:
    186 {{{
     150For [wiki:TracModPython mod_python]:
     151{{{#!apache
    187152PythonOption TracEnvParentDir /parent/dir/of/projects
    188153PythonOption TracEnvIndexTemplate /path/to/template
    189154}}}
    190155
    191 [wiki:TracCgi CGI] 用:
    192 {{{
     156For [wiki:TracCgi CGI]:
     157{{{#!apache
    193158SetEnv TRAC_ENV_INDEX_TEMPLATE /path/to/template
    194159}}}
    195160
    196 [wiki:TracStandalone] の tracd を動かすのに使用するシェルの中で `TRAC_ENV_INDEX_TEMPLATE` の環境変数を設定する必要があるでしょう:
    197  - Unix
    198    {{{
    199 #!sh
     161For [wiki:TracStandalone], you'll need to set up the `TRAC_ENV_INDEX_TEMPLATE` environment variable in the shell used to launch tracd:
     162 - Unix:
     163   {{{#!sh
    200164$ export TRAC_ENV_INDEX_TEMPLATE=/path/to/template
    201165   }}}
    202  - Windows
    203    {{{
    204 #!sh
     166 - Windows:
     167   {{{#!sh
    205168$ set TRAC_ENV_INDEX_TEMPLATE=/path/to/template
    206169   }}}
    207170
    208 == プロジェクトテンプレート == #ProjectTemplates
     171== Project Templates
    209172
    210 個々の Trac Environment (プロジェクトのインスタンス) の外観は、同じサーバにホストされている他のプロジェクトとは独立してカスタマイズできます。推奨するのは `site.html` テンプレート ([#SiteAppearance サイトの外観] 参照) を使う方法です。どのような場合でも可能な限り、この方法にしてください。 `site.html` を使う場合、変更はオリジナルのテンプレートがレンダリングした結果に対して適用されるので、 Trac を今後アップグレードした後も、通常はカスタマイズをそのまま使い続けることができます。 `theme.html` や他の Trac のテンプレートのコピーを作成する方法の場合、新しい Trac の機能追加や不具合修正の結果、動かなくなってしまったカスタマイズを新しいバージョンに移行する必要があるかもしれません。
     173The appearance of each individual Trac environment, ie instance of a project, can be customized independently of other projects, even those hosted on the same server. The recommended way is to use a `site.html` template whenever possible, see [#SiteAppearance]. Using `site.html` means changes are made to the original templates as they are rendered, and you should not normally need to redo modifications whenever Trac is upgraded. If you do make a copy of `theme.html` or any other Trac template, you need to migrate your modifiations to the newer version. If not, new Trac features or bug fixes may not work as expected.
    211174
    212 リスクを許容して扱う必要はありますが、 Trac テンプレートはコピーしてカスタマイズすることもできます。デフォルトの Trac テンプレートはインストールされた Trac egg (`/usr/lib/pythonVERSION/site-packages/Trac-VERSION.egg/trac/templates, .../trac/ticket/templates, .../trac/wiki/templates, ++`) 内に配置されています。 [#ProjectList プロジェクトリスト] のテンプレートファイルは `index.html` が使用されており、各ページに共通する主要なレイアウトを提供するテンプレートは `theme.html` が使用されます。画像や CSS スタイルシートなどのページの部品は、 egg の `trac/htdocs` ディレクトリに配置されています。
     175With that word of caution, any Trac template may be copied and customized. The default Trac templates are located inside the installed Trac egg, such as `/usr/lib/pythonVERSION/site-packages/Trac-VERSION.egg/trac/templates, ../trac/ticket/templates, ../trac/wiki/templates`. The [#ProjectList] template file is called `index.html`, while the template responsible for main layout is called `theme.html`. Page assets such as images and CSS style sheets are located in the egg's `trac/htdocs` directory.
    213176
    214 しかし、 Trac egg 内部のテンプレートやサイトのリソースは編集しないでください。 Trac を再インストールしたときに、カスタマイズの内容が完全に失われてしまいます。代わりに、以下に挙げる方法のいずれかを使ってください:
    215  * カスタマイズが単独のプロジェクトに閉じているのであれば、テンプレートをプロジェクトの `templates` ディレクトリにコピーしてください
    216  * カスタマイズが複数のプロジェクトに渡るものであるなら、テンプレートを共有のロケーションにコピーし、各プロジェクトからは trac.ini の `[inherit] templates_dir =` オプションで、その位置を指定してください
     177However, do not edit templates or site resources inside the Trac egg. Reinstalling Trac overwrites your modifications. Instead use one of these alternatives:
     178 * For a modification to one project only, copy the template to project `templates` directory.
     179 * For a modification shared by several projects, copy the template to a shared location and have each project point to this location using the `[inherit] templates_dir` trac.ini option.
    217180
    218 Trac は以下の順序で、テンプレートファイルを探します。まず、プロジェクトの内部を探し、存在しなければ inherit で指定された場所、最後に Trac egg の内部を探します。
     181Trac resolves requests for a template by first looking inside the project, then in any inherited templates location, and finally inside the Trac egg.
    219182
    220 Trac は通常、パフォーマンスを向上させるために、テンプレートをメモリ上にキャッシュします。変更したテンプレートを適用するためには、 サーバプロセスの再起動が必要です。
     183Trac caches templates in memory by default to improve performance. To apply a template you need to restart the web server.
    221184
    222185----
    223 See also: TracGuide, TracIni
     186See also TracGuide, TracIni