I found most of the structure of .po files at the GNU Gettext manual. But the manual doesn't say anything about how to set a header.
How do I make a header for gettext .po files?
Thanks
If I were you I would just download an example .po file and have a look inside with a regular text editor.
The header contains the following information :
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL#ADDRESS>, YEAR.
#
#: src/link/to/my/src:67
msgid ""
msgstr ""
"Project-Id-Version: xxx\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-07-06 12:31-0500\n"
"PO-Revision-Date: 2011-05-27 22:37+0100\n"
"Last-Translator: My NAME<me#mydomain.com>\n"
"Language-Team: TEAM <team#TTEAM.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Then, the inside is organized this way :
# This is a comment
# and another line of comment
msgid "This is my original string to translate"
msgstr "Translation goes here ... "
# TRANSLATED : Mon Jun 14 09:36:07 2010
# TRANSLATOR : MyName goes here... it's a comment
#: src/main/my/source/reference/:34
msgid "Get started now!"
msgstr "Commencez dès maintenant!"
Hope this helps...
Found out the way to set the charset is as simple as putting "Content-Type: text/plain; charset=utf8" in the file.
The most minimal header you can use is to just use
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
but in most cases you want at least this:
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
All the other stuff you can have there (copyright comments or other metadata) is optional. And if you don't need plurar support, the Plural-Forms is obviously not needed either.
Related
We want to add another language to the Cumulocity plattform. We received the *.po file for our UI Version from the support and generated a test translation to check how it works before ordering the translation. We got the info that we can just put the *.po file to an app or a widget and when deployed, the translation should be visible for the whole platform, but that does not seem to work, do we have to set a reference or something somewhere inside of the app or widget to the po file or is there another aspect we should take a look at?
Best Regards
Our Translationfile contains following header for now:
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-Basepath: .\n"
"X-Generator: Poedit 2.2\n"
msgid "\"{{c8y_Dashboard.name}}\" - dashboard"
msgstr "\"{{c8y_Dashboard.name}}\"-往好处说是超脱豁达"
msgid "\"{{c8y_Kpi.label}}\" - data point"
msgstr "\"{{c8y_Kpi.label}}\"-北洋军阀从白走到黑"
[...]
Try to put the po file into a folder "locales" into your plugin and run the build. Here's an example that worked for me: https://bitbucket.org/m2m/cumulocity-ui-plugin-examples/src/bac470cb8149/plugins/weather
I want to switch the string from translated string in .po file to original string in source file.
i.e:
in en.po
#: hello.py:100
msgid "안녕"
msgstr "hello"
in hello.py
...
print(_(u'안녕'))
....
something --pofile en.po --source [directory in hello.py] --destination [directory for hello_replaced.py]
it will be :
in hello_replaced.py
...
print(_(u'hello'))
...
Is there any useful tool?
My src\Locale\pr_IR file is like
msgid "Mobile"
msgstr "موبایل"
msgid "mobile"
msgstr "موبایل"
msgid "MoBiLe"
msgstr "موبایل"
Is it possible to convert this to something like
msgid "Mobile"
msgid "mobile"
msgid "MoBiLe"
msgstr "موبایل"
No it's not, at least not without creating your own PO file parser that would handle such an invalid/non-standard PO format.
See also
Cookbook > Internationalization & Localization > Creating Message Parsers
http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files
Multiple "msgid" for an "msgstr" in gettext
I am trying to localize an existing Ruby on Rails project, and I have decided to use fast_gettext. I have tried to set things up as described on the github page (https://github.com/grosser/fast_gettext) and in this small tutorial (http://blog.lingohub.com/developers/2013/08/ruby-gettext-internationalization-tutorial-fest-gettext-gem/). However, when I do
rake gettext:find
it appears that only my .rb files are being searched and not my other files (importantly, the .erb files are not being checked).
In addition to updating my bundle to include the necessary gems, this is what I've done so far:
Added config/initializers/fast_gettext.rb. Here it is:
# config/initializers/fast_gettext.rb
FastGettext.add_text_domain 'app', :path => 'config/locales', :type => :yaml
FastGettext.default_available_locales = ['en','es']
FastGettext.default_text_domain = 'app'
I have also created lib/tasks/gettext.rake
namespace :gettext do
def files_to_translate
Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}")
end
end
This is index.html.erb
<div class="home_title"><%= t(:xyz) %></div>
I am setting the locale in application_controller.rb, and if I manually modify the locale file (e.g. config/locales/es.yml), the text gets translated when I open the page. However, when I run gettext, it does not create an entry for this item. I end up with an empty app.pot:
# File headers....
# Copyright, my name, etc.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: app 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-03-19 16:52-0700\n"
"PO-Revision-Date: 2014-03-19 16:52-0700\n"
"Last-Translator: FULL NAME <EMAIL#ADDRESS>\n"
"Language-Team: LANGUAGE <LL#li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
As I said above, I believe that gettext is only checking .rb files (based on some hacked logs that I placed inside the gettext code). It could also be that I need to do something extra to configure gettext to recognize this is a string to be localized:
<%= t(:xyz) %>
Thanks in advance for your suggestions.
I have an email extracted from an IMAP account. I have encoded it like this:
body = imap.uid_fetch(uid, "BODY[TEXT]")[0].attr["BODY[TEXT]"].force_encoding('UTF-8')
So now it looks like this:
puts body.inspect => "\n--Apple-Mail-028364EC-0K8B-4FD7-87E8-97C28C324717\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: quoted-printable\n\nHej=20\n\nI m=C3=A5 meget undskylde men jeg vil ikke k=C3=B8be produktet alligevel hvord=\nan g=C3=B8r vi det...=20\n\nHans Nielsen. =20\nR=C3=B8rgade 65=20\n1234 G=C3=B8rlev\n\n"
I want to present the email in my Rails app, so the user of the app can review the email. But how do I clean up the body?
I want to remove this part:
--Apple-Mail-028364EC-0K8B-4FD7-87E8-97C28C324717
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
And clean up this part:
Hej=20
I m=C3=A5 meget undskylde men jeg vil ikke k=C3=B8be produktet alligevel hvord=
an g=C3=B8r vi det...=20
Hans Nielsen. =20
R=C3=B8rgade 65=20
1234 G=C3=B8rlev
This means replacing the weird characters with the originally intended characters. Fyi, these are:
=C3=A5 is å
=C3=B8 is ø
=20 is ???
= is ???
How to do this (without just using gsub)?
You need to use a MIME parser, which should take care of removing the headers and getting rid of the quoted printable encoding. Depending on the layout of your email, body[text] might get you a lot more than you want. You need to either download the BODYSTRUCTURE and pick out the parts you want, or download the entire message (BODY[]) and use a MIME parser.
The decoding result is:
Hej
I må meget undskylde men jeg vil ikke købe produktet alligevel hvordan gør vi det...
Hans Nielsen.
Rørgade 65
1234 Gørlev
It seems that = is ... and =20 is "\n".