diff options
author | Doug Hellmann <doug.hellmann@dreamhost.com> | 2014-05-07 12:04:27 -0700 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@dreamhost.com> | 2014-05-07 12:43:47 -0700 |
commit | 0e4a3db114a03523443089f98a0b4f010ab78485 (patch) | |
tree | 7bb363381e5e9680afe4ee87e73728f52a9aa01d | |
parent | e5c7982327b757cecf65ce2666f378843a7200fc (diff) | |
download | oslo-i18n-0e4a3db114a03523443089f98a0b4f010ab78485.tar.gz |
Fix up usage instructions
Clean up the documentation a little bit and write slightly
more verbose (and correct) instructions for using the library.
bp graduate-oslo-i18n
Change-Id: Ice626b6eae3c02be84cf79a1ad57817ec8736d8a
-rw-r--r-- | README.rst | 8 | ||||
-rw-r--r-- | doc/source/readme.rst | 2 | ||||
-rw-r--r-- | doc/source/usage.rst | 42 | ||||
-rw-r--r-- | oslo/i18n/gettextutils.py | 7 |
4 files changed, 43 insertions, 16 deletions
@@ -1,10 +1,10 @@ -=================================== -oslo.i18n -=================================== +=========== + oslo.i18n +=========== oslo.i18n library * Free software: Apache license * Documentation: http://docs.openstack.org/developer/oslo.i18n * Source: http://git.openstack.org/cgit/openstack/oslo.i18n -* Bugs: http://bugs.launchpad.net/oslo
\ No newline at end of file +* Bugs: http://bugs.launchpad.net/oslo diff --git a/doc/source/readme.rst b/doc/source/readme.rst index 6b2b3ec..a6210d3 100644 --- a/doc/source/readme.rst +++ b/doc/source/readme.rst @@ -1 +1 @@ -.. include:: ../README.rst
\ No newline at end of file +.. include:: ../../README.rst diff --git a/doc/source/usage.rst b/doc/source/usage.rst index 3a368fe..9ea3fa0 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -1,7 +1,39 @@ -======== -Usage -======== +======= + Usage +======= -To use in a project:: +To use in a project, create a small integration module containing: - import i18n
\ No newline at end of file +:: + + from oslo.i18n import gettextutils + + _translators = gettextutils.TranslatorFactory(domain='myapp') + + # The primary translation function using the well-known name "_" + _ = _translators.primary + + # Translators for log levels. + # + # The abbreviated names are meant to reflect the usual use of a short + # name like '_'. The "L" is for "log" and the other letter comes from + # the level. + _LI = _translators.log_info + _LW = _translators.log_warning + _LE = _translators.log_error + _LC = _translators.log_critical + +Then, in your application code, use the appropriate marker function +for your case: + +:: + + from myapp.i18n import _, _LW + + # ... + + LOG.warn(_LW('warning message: %s'), var) + + # ... + + raise RuntimeError(_('exception message')) diff --git a/oslo/i18n/gettextutils.py b/oslo/i18n/gettextutils.py index 58231e0..43f45ee 100644 --- a/oslo/i18n/gettextutils.py +++ b/oslo/i18n/gettextutils.py @@ -14,12 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -""" -gettext for openstack-common modules. - -Usual usage in an openstack.common module: - - from openstack.common.gettextutils import _ +"""gettextutils provides a wrapper around gettext for OpenStack projects """ import copy |