From Fedora Project Wiki
(Slarify wording a little)
(describe most common find_lang options & rework the example)
 
Line 8: Line 8:
</pre>
</pre>


For Qt-based packages that use the Linguist tool chain, the localisation utilities add
For Qt-based packages that use the Linguist tool chain, for the localisation utilities add
<pre>
<pre>
BuildRequires: qt-devel
BuildRequires: qt-devel
Line 17: Line 17:
%find_lang %{name}
%find_lang %{name}
</pre>
</pre>
In some cases, the application may use a different "name" for its locales. You may have to look at the locale files and see what they are named. If they are named <code>myapp.mo</code>, then you will need to pass <code>myapp</code> to <code>%find_lang</code> instead of <code>%{name</code>}.
In some cases, the application may use a different "name" for its locales. You may have to look at the locale files and see what they are named. If they are named <code>myapp.mo</code>, then you will need to pass <code>myapp</code> to <code>%find_lang</code> instead of <code>%{name}</code>.
After <code>%find_lang</code> is run, it will generate a file in the active directory (by default, the top level of the source dir). This file will be named based on what you passed as the option to the <code>%find_lang</code> macro. Usually, it will be named <code>%{name}.lang</code>. You should then use this file in the <code>%files</code> list to include the locales detected by <code>%find_lang</code>. To do this, you should include it with the -f parameter to <code>%files</code>.
After <code>%find_lang</code> is run, it will generate a file in the active directory (by default, the top level of the source dir). This file will be named based on what you passed as the option to the <code>%find_lang</code> macro. Usually, it will be named <code>%{name}.lang</code>. You should then use this file in the <code>%files</code> list to include the locales detected by <code>%find_lang</code>. To do this, you should include it with the -f parameter to <code>%files</code>.
<pre>
<pre>
Line 24: Line 24:
...
...
</pre>
</pre>
If you are already using the -f parameter for the <code>%files</code> section where the locales should live, just append the contents of <code>%{name}.lang</code> to the end of the file that you are already using with -f. (Note that only one file may be used with <code>%files -f</code>.)


Here is an example of proper usage of <code>%find_lang</code>, in <code>foo.spec</code>:
Note that <code>%find_lang</code> by default searches for gettext locales, but it can also handle Qt translations, localised manpages and help files.


To process GNOME help files put into <code>/usr/share/gnome/help/</code> use
<pre>
<pre>
%find_lang %{name} --with-gnome
</pre>
To process KDE help files put into <code>/usr/share/doc/HTML/</code> use
<pre>
%find_lang %{name} --with-kde
</pre>
To process Qt's <code>.qm</code> binary translation files use
<pre>
%find_lang %{name} --with-qt
</pre>
To process localised manpages (doesn't include the default, non-localised one), use
<pre>
%find_lang %{name} --with-man
</pre>
To see all the options, run <code>/usr/lib/rpm/find-lang.sh</code> in the terminal.
Names different from <code>%{name}</code> (e.g. multiple manpages) must be handled via separate calls to <code>%find_lang</code>.
Here is an example of proper usage of <code>%find_lang</code>, in <code>foo.spec</code> with the "foo" application localised using gettext and man pages named "bar" instead of "foo":
<pre>
Name: foo
...
...
%prep
%prep
Line 40: Line 66:
make DESTDIR=%{buildroot} install
make DESTDIR=%{buildroot} install
%find_lang %{name}
%find_lang %{name}
%find_lang bar --with-man


%files -f %{name}.lang
%files -f %{name}.lang -f bar.lang
%doc LICENSE README
%doc LICENSE README
%{_bindir}/foobar
%{_bindir}/%{name}
%{_mandir}/man1/bar.1.gz                                                                                                                                                                                       


%changelog
%changelog
* Fri Jan 13 2012 Karel Volny <kvolny@redhat.com> 0.1-2
- add man pages example
* Thu May 4 2006 Tom "spot" Callaway <tcallawa@redhat.com> 0.1-1
* Thu May 4 2006 Tom "spot" Callaway <tcallawa@redhat.com> 0.1-1
- sample spec that uses %%find_lang
- sample spec that uses %%find_lang


</pre>
</pre>
Note that <code>%find_lang</code> by default searches for gettext locales, but it can also handle Qt translations, localised manpages and help files - to see all the options, run <code>/usr/lib/rpm/find-lang.sh</code> in the terminal.


[[Category:Packaging guidelines drafts]]
[[Category:Packaging guidelines drafts]]

Latest revision as of 11:56, 13 January 2012

Handling Locale Files

Translation files may be handled by different programs for different frameworks. Make sure you BuildRequire the correct package or else your package could fail to generate translation files in the buildroot.

If the package uses gettext for translations, add

BuildRequires: gettext

For Qt-based packages that use the Linguist tool chain, for the localisation utilities add

BuildRequires: qt-devel

Fedora includes an rpm macro called %find_lang. This macro will locate all of the locale files that belong to your package (by name), and put this list in a file. You can then use that file to include all of the locales. %find_lang should be run in the %install section of your spec file, after all of the files have been installed into the buildroot. The correct syntax for %find_lang is usually:

%find_lang %{name}

In some cases, the application may use a different "name" for its locales. You may have to look at the locale files and see what they are named. If they are named myapp.mo, then you will need to pass myapp to %find_lang instead of %{name}. After %find_lang is run, it will generate a file in the active directory (by default, the top level of the source dir). This file will be named based on what you passed as the option to the %find_lang macro. Usually, it will be named %{name}.lang. You should then use this file in the %files list to include the locales detected by %find_lang. To do this, you should include it with the -f parameter to %files.

%files -f %{name}.lang
%{_bindir}/foobar
...

Note that %find_lang by default searches for gettext locales, but it can also handle Qt translations, localised manpages and help files.

To process GNOME help files put into /usr/share/gnome/help/ use

%find_lang %{name} --with-gnome

To process KDE help files put into /usr/share/doc/HTML/ use

%find_lang %{name} --with-kde

To process Qt's .qm binary translation files use

%find_lang %{name} --with-qt

To process localised manpages (doesn't include the default, non-localised one), use

%find_lang %{name} --with-man

To see all the options, run /usr/lib/rpm/find-lang.sh in the terminal.

Names different from %{name} (e.g. multiple manpages) must be handled via separate calls to %find_lang.

Here is an example of proper usage of %find_lang, in foo.spec with the "foo" application localised using gettext and man pages named "bar" instead of "foo":

Name: foo
...
%prep
%setup -q

%build
%configure --with-cheese
make %{?_smp_mflags}

%install
make DESTDIR=%{buildroot} install
%find_lang %{name}
%find_lang bar --with-man

%files -f %{name}.lang -f bar.lang
%doc LICENSE README
%{_bindir}/%{name}
%{_mandir}/man1/bar.1.gz                                                                                                                                                                                        

%changelog
* Fri Jan 13 2012 Karel Volny <kvolny@redhat.com> 0.1-2
- add man pages example

* Thu May 4 2006 Tom "spot" Callaway <tcallawa@redhat.com> 0.1-1
- sample spec that uses %%find_lang