Читаем Linux программирование в примерах полностью

#: ch13-echodate.c:19 /* Местоположение сообщения */

msgid "Enter a Date/time as YYYY/MM/DD HH:MM:SS : " /* Оригинальное

                                                       сообщение */

msgstr "" /* Здесь перевод */

#: ch13-echodate.с:32 /* To же самое для каждого сообщения */

#, с-format

msgid "Got: %s"

msgstr ""

Этот первоначальный файл используется повторно для каждого перевода. Таким образом, это шаблон для переводов, и по соглашению, для отображения этого факта он должен быть переименован с расширением .pot (portable object template — переносимый объектный шаблон):

$ mv echodate.ро echodate.pot

He владея свободно несколькими языками, мы решили перевести сообщения на свинский латинский. Следующим шагом является создание перевода. Это осуществляется копированием файла шаблона и добавлением к новой копии перевода:

$ cp echodate.pot piglat.po

$ vi piglat.po /* Добавить переводы, используя любимый редактор */

Имя по соглашению должно быть язык.po, где язык является стандартным международным сокращением из двух или трех букв для обозначения языка. Иногда используется форма язык_страна.po: например, pt_BR.po для португальского в Бразилии. Поскольку свинский латинский не является настоящим языком, мы назвали файл piglat.ро.[147] Вот содержание после добавления перевода:

# echodate translations into pig Latin

# Copyright (C) 2004 Prentice-Hall

# This file is distributed under the same license as the echodate package.

# Arnold Robbins 2004

#

#, fuzzy

msgid ""

msgstr ""

"Project-Id-Version: echodate 1.0\n"

"Report-Msgid-Bugs-To: arnold@example.com\n"

"POT-Creation-Date: 2003-07-14 18:46-0700\n"

"PO-Revision-Date: 2003-07-14 19:00+8\n"

"Last-Translator: Arnold Robbins \n"

"Language-Team: Pig Latin \n"

"MIME-Version: 1.0\n"

"Content-Type: text/plain; charset=ASCII\n"

"Content-Transfer-Encoding: 8bit\n"

#: ch13-echodate.с:19

msgid "Enter a Date/time as YYYY/MM/DD HH:MM:SS : "

msgstr "Enteray A Ateday/imetay asay YYYY/MM/DD HH:MM:SS : "

#: ch13-echodate.c:32

#, c-format

msgid "Got: %s"

msgstr "Otgay: %s"

Хотя можно было бы произвести линейный поиск в переносимом объектном файле, такой поиск был бы медленным. Например, в gawk имеется примерно 350 отдельных сообщений, а в GNU Coreutils — свыше 670. Линейный поиск в файле с сотнями сообщений был бы заметно медленным. Поэтому GNU gettext использует для быстрого поиска сообщений двоичный формат. Сравнение осуществляет msgfmt, выдавая объектный файл сообщений:

$ msgfmt piglat.po -о piglat.mo

При сопровождении программы изменяются строки, используемые программой: добавляются новые, другие удаляются или изменяются. По крайней мере, может измениться положение строки в исходном файле. Таким образом, файлы переводов .ро, вероятно, устареют. Программа msgmerge объединяет старые файлы переводов с новым файлом .pot. Затем результат может быть обновлен. Этот пример выполняет объединение и повторное компилирование:

$ msgmerge piglat.po echodate.pot -o piglat.new.po /* Объединить файлы */

$ mv piglat.new.po piglat.po /* Переименовать результат */

$ vi piglat.po /* Модернизировать перевод */

$ msgfmt piglat.po -o piglat.mo /* Восстановить файл .mo */

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных