Coding

Differences between revisions 1 and 7 (spanning 6 versions)
Revision 1 as of 2009-12-05 16:22:27
Size: 250
Editor: 212
Comment:
Revision 7 as of 2010-01-27 09:21:53
Size: 6402
Editor: 168
Comment:
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
~-[[UbuntuDevelopment|Ubuntu Development]] > [[UbuntuDevelopment/Internationalisation|Internationalization Guide]] > Coding -~

'''STILL IN DRAFT STATUS'''

=== Recommended directory layout ===

==== General ====

 * Mention `po` and `help/po`
 * Mention where .desktop.in and other internationalizable files, etc. are recommended to go

==== If you are supporting multiple graphical toolkits ====

 * Mention `gtk` and `qt`

=== Individual programming languages ===

==== C application, using automake and intltool ====

===== Changes in configure.ac =====

{{{
GETTEXT_PACKAGE=your-application-domain-name
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [gettext package name])
AM_GLIB_GNU_GETTEXT

# AM_GNOME_GETTEXT above substs $DATADIRNAME
# this is the directory where the *.{mo,gmo} files are installed
localedir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(localedir)

IT_PROG_INTLTOOL([0.40.0])

AC_OUTPUT([
po/Makefile.in
])
}}}

===== Changes in Makefile.am =====

====== General ======

{{{
SUBDIRS = po
}}}

====== If you are using Freedesktop.org desktop entries ======

{{{
desktopdir = $(datadir)/applications
desktop_in_files = yourappname.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@

EXTRA_DIST = \
 $(desktop_in_files) \

DISTCLEANFILES = \
 $(desktop_DATA) \
}}}

====== If you are using Gconf schema files ======

{{{
schema_in_files = yourappname.schemas.in
schemadir = @GCONF_SCHEMA_FILE_DIR@
schema_DATA = $(schema_in_files:.schemas.in=.schemas)
@INTLTOOL_SCHEMAS_RULE@

EXTRA_DIST = \
 $(schema_in_files) \

DISTCLEANFILES = \
 $(schema_DATA) \
}}}

 * Marking the files for internationalisation:

====== If you are using Policykit policy files ======

{{{
policydir = $(YOURAPPS_POLICY_DIR)
policy_in_files = yourappname.policy.in
policy_DATA = $(policy_in_files:.policy.in=.policy)

@INTLTOOL_POLICY_RULE@

EXTRA_DIST = \
 $(policy_in_files) \

DISTCLEANFILES = \
 $(policy_DATA)
}}}

 * Marking them for internationalisation: TODO: prepare a separate section on policy files, including the snippet below

{{{
  <action id="org.freedesktop.systemtoolsbackends.set">
    <_description>Manage system configuration</_description>
    <_message>System policy prevents modifying the configuration</_message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin</allow_active>
    </defaults>
  </action>
}}}

===== Other required files =====

 * po/LINGUAS
 * po/POTFILES.in
 * [optional] po/POTFILES.skip

===== Code changes =====

====== Enabling gettext ======

====== Marking strings for translation ======

 * Mention gettext _()
 * Mention ngettext

==== Python application, using automake and intltool ====

==== Python application, using pyton-distutils-extra ====

=== Translator comments ===

=== Translator credits ===

==== GTK ====

==== KDE ====

==== Launchpad ====

<<Anchor(LPI)>>
=== Launchpad integration library ===

Ubuntu applications use the [[https://launchpad.net/launchpad-integration|Launchpad integration library]] to provide shortcuts to Launchpad to obtain help, report bugs and submit translations. You can see it in action in any Ubuntu application's Help menu:

{{attachment:../LPI.png}}

It has bindings for several languages, for example, here's how Launchpad integration was [[Bug:508395|added to Pitivi]] in '''Python'''.

There are no '''C#''' bindings at the moment but [[Bug:507777|they are currently under way]].

Here's an example in '''C''' of how support for this library was [[Bug:436742|added to Empathy]]:

{{{
#!diff
=== modified file 'configure.ac'
--- configure.ac 2009-10-13 03:20:58 +0000
+++ configure.ac 2009-10-13 03:26:58 +0000
@@ -131,6 +131,7 @@
    gstreamer-0.10
    unique-1.0
    gnome-keyring-1 >= $KEYRING_REQUIRED
+ launchpad-integration
 ])
 
 PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)

=== modified file 'src/empathy-main-window.c'
--- src/empathy-main-window.c 2009-10-13 03:20:58 +0000
+++ src/empathy-main-window.c 2009-10-13 18:15:41 +0000
@@ -27,6 +27,9 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
+/* Add launchpad hooks */
+#include <launchpad-integration.h>
+
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-account-manager.h>
@@ -1424,6 +1427,9 @@
 
  main_window_update_status (window, window->account_manager);
 
+ /* Add launchpad hooks */
+ launchpad_integration_add_ui (window->ui_manager, "/menubar/help/LaunchpadItems");
+
  return window->window;
 }
 

=== modified file 'src/empathy-main-window.ui'
--- src/empathy-main-window.ui 2009-10-13 03:19:42 +0000
+++ src/empathy-main-window.ui 2009-10-13 18:17:20 +0000
@@ -243,6 +243,7 @@
         <menu action="help">
           <menuitem action="help_contents"/>
           <menuitem action="help_debug"/>
+ <placeholder name="LaunchpadItems"/>
           <menuitem action="help_about"/>
         </menu>
       </menubar>
}}}

=== Additional documentation ===

 * [[http://www.gnu.org/software/gettext/manual/gettext.html|Gettext documentation]]
 * [[http://www.gnu.org/s/libc/manual/html_node/Message-catalogs-with-gettext.html| The GNU libc documentation on Gettext]]
 * [[http://live.gnome.org/TranslationProject/DevGuidelines|GNOME l10n guidelines for developers]] and the [[http://live.gnome.org/TranslationProject|GNOME Translation Project]]
 * [[http://docs.python.org/library/gettext.html|Python gettext module documentation]]
 * [[http://www.doughellmann.com/PyMOTW/gettext/|Doug Hellmann's article on the Python gettext module]]
 * [[http://www.openi18n.org/docs/html/LI18NUX-2000-amd4.htm|LI18NUX 2000 Globalization Specification]]
 * [[http://www.openi18n.org/docs/text/LocNameGuide-V10.txt|OpenI18N Locale Name Guideline]]
 * [[http://www.linux.com/archive/feature/53781|Bill Poser's "Controlling your locale with environment variables" article]]

Ubuntu Development > Internationalization Guide > Coding

STILL IN DRAFT STATUS

General

  • Mention po and help/po

  • Mention where .desktop.in and other internationalizable files, etc. are recommended to go

If you are supporting multiple graphical toolkits

  • Mention gtk and qt

Individual programming languages

C application, using automake and intltool

Changes in configure.ac

GETTEXT_PACKAGE=your-application-domain-name
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [gettext package name])
AM_GLIB_GNU_GETTEXT

# AM_GNOME_GETTEXT above substs $DATADIRNAME
# this is the directory where the *.{mo,gmo} files are installed
localedir='${prefix}/${DATADIRNAME}/locale'
AC_SUBST(localedir)

IT_PROG_INTLTOOL([0.40.0])

AC_OUTPUT([
po/Makefile.in
])

Changes in Makefile.am

General

SUBDIRS = po

If you are using Freedesktop.org desktop entries

desktopdir = $(datadir)/applications
desktop_in_files = yourappname.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@

EXTRA_DIST = \
        $(desktop_in_files)      \

DISTCLEANFILES = \
        $(desktop_DATA) \

If you are using Gconf schema files

schema_in_files = yourappname.schemas.in
schemadir = @GCONF_SCHEMA_FILE_DIR@
schema_DATA = $(schema_in_files:.schemas.in=.schemas)
@INTLTOOL_SCHEMAS_RULE@

EXTRA_DIST = \
        $(schema_in_files)      \

DISTCLEANFILES = \
        $(schema_DATA) \
  • Marking the files for internationalisation:

If you are using Policykit policy files

policydir = $(YOURAPPS_POLICY_DIR)
policy_in_files = yourappname.policy.in
policy_DATA = $(policy_in_files:.policy.in=.policy)

@INTLTOOL_POLICY_RULE@

EXTRA_DIST = \
        $(policy_in_files) \

DISTCLEANFILES = \
        $(policy_DATA)
  • Marking them for internationalisation: TODO: prepare a separate section on policy files, including the snippet below

  <action id="org.freedesktop.systemtoolsbackends.set">
    <_description>Manage system configuration</_description>
    <_message>System policy prevents modifying the configuration</_message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin</allow_active>
    </defaults>
  </action>

Other required files
  • po/LINGUAS
  • po/POTFILES.in
  • [optional] po/POTFILES.skip

Code changes

Enabling gettext

Marking strings for translation
  • Mention gettext _()
  • Mention ngettext

Python application, using automake and intltool

Python application, using pyton-distutils-extra

Translator comments

Translator credits

GTK

KDE

Launchpad

Launchpad integration library

Ubuntu applications use the Launchpad integration library to provide shortcuts to Launchpad to obtain help, report bugs and submit translations. You can see it in action in any Ubuntu application's Help menu:

../LPI.png

It has bindings for several languages, for example, here's how Launchpad integration was added to Pitivi in Python.

There are no C# bindings at the moment but they are currently under way.

Here's an example in C of how support for this library was added to Empathy:

   1 === modified file 'configure.ac'
   2 --- configure.ac        2009-10-13 03:20:58 +0000
   3 +++ configure.ac        2009-10-13 03:26:58 +0000
   4 @@ -131,6 +131,7 @@
   5     gstreamer-0.10
   6     unique-1.0
   7     gnome-keyring-1 >= $KEYRING_REQUIRED
   8 +   launchpad-integration
   9  ])
  10  
  11  PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)
  12 
  13 === modified file 'src/empathy-main-window.c'
  14 --- src/empathy-main-window.c   2009-10-13 03:20:58 +0000
  15 +++ src/empathy-main-window.c   2009-10-13 18:15:41 +0000
  16 @@ -27,6 +27,9 @@
  17  #include <gtk/gtk.h>
  18  #include <glib/gi18n.h>
  19  
  20 +/* Add launchpad hooks */
  21 +#include <launchpad-integration.h>
  22 +
  23  #include <libempathy/empathy-contact.h>
  24  #include <libempathy/empathy-utils.h>
  25  #include <libempathy/empathy-account-manager.h>
  26 @@ -1424,6 +1427,9 @@
  27  
  28         main_window_update_status (window, window->account_manager);
  29  
  30 +       /* Add launchpad hooks */
  31 +       launchpad_integration_add_ui (window->ui_manager, "/menubar/help/LaunchpadItems");
  32 +
  33         return window->window;
  34  }
  35  
  36 
  37 === modified file 'src/empathy-main-window.ui'
  38 --- src/empathy-main-window.ui  2009-10-13 03:19:42 +0000
  39 +++ src/empathy-main-window.ui  2009-10-13 18:17:20 +0000
  40 @@ -243,6 +243,7 @@
  41          <menu action="help">
  42            <menuitem action="help_contents"/>
  43            <menuitem action="help_debug"/>
  44 +          <placeholder name="LaunchpadItems"/>
  45            <menuitem action="help_about"/>
  46          </menu>
  47        </menubar>

Additional documentation


CategoryUbuntuDevelopment CategoryTranslations

UbuntuDevelopment/Internationalisation/Coding (last edited 2010-02-18 10:50:22 by 28)