Django .po translation - poedit

I have used the following .po file in Poedit to use it in a django app (locale\el\LC_MESSAGES\django.po) for greek characters in templates.
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 , YEAR.
msgid "" msgstr "" "Project-Id-Version: Apografi\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2016-05-04
11:27+0300\n" "PO-Revision-Date: 2016-05-09 09:51+0200\n"
"Last-Translator: Kostas \n" "Language-Team: LANGUAGE
\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-Generator: Poedit 1.6.4\n"
"X-Poedit-SourceCharset: UTF-8\n" "Language: el_GR\n"
: .\templates\widgets\tables\tables.html:69 msgid "%(count)s of %(total)s" msgstr "%(count)s από %(total)s"
: .\templates\category\create.html:16 .\templates\authority\create.html:16
: .\templates\division\create.html:16 msgid "Create" msgstr "Δημιουργία"
: .\templates\category\update.html:17 .\templates\authority\update.html:17
: .\templates\division\update.html:16 msgid "Update" msgstr "Ενημέρωση"
: .\templates\category\delete.html:15 .\templates\authority\delete.html:15
: .\templates\division\delete.html:15 msgid "Delete" msgstr "Διαγραφή"
: .\templates\category\delete.html:18 .\templates\authority\delete.html:18
: .\templates\division\delete.html:18 msgid "Are you sure you want to delete the selected" msgstr "Θέλετε να διαγράψετε την επιλεγνένη
εγγραφή"
: .\templates\widgets\form.html:18 msgid "Save" msgstr "Αποθήκευση"
: .\templates\authority\detail.html:34 .\templates\division\detail.html:34
: .\templates\category\detail.html:34 msgid "pedio" msgstr "Όνομα Πεδίου"
: .\templates\authority\detail.html:35 .\templates\division\detail.html:35
: .\templates\category\detail.html:35 msgid "timh" msgstr "Τιμή Πεδίου"
: .\templates\division\list.html:15 .\templates\authority\list.html:15
: .\templates\category\list.html:15 msgid "Add" msgstr "Προσθήκη"
: .\templates\division\list.html:25 .\templates\authority\list.html:25
: .\templates\category\list.html:25 msgid "Search" msgstr "Αναζήτηση"
msgid "apografi" msgstr "Απογραφή"
msgid "category" msgstr "Κατηγορία"
msgid "authority" msgstr "Διεύθυνση"
msgid "division" msgstr "Τμήμα"
Using the validation of Poedit showed me No erros that validation is OK and translation file should be used.
This .po file works for 90% OK for me but when i try to use trans inside these bootstrap tags i do not get translated result but the source:
1.
table class="table table-bordered">
thead
tr
th{% trans "pedio" %}/th
th{{ _("timh") }}/th
/tr
/thead
2.
a class="btn btn-primary pull-right"> {{ _("Update") }} /a
a class="btn btn-primary
pull-right"> {{ _("Delete")
}} /a

Where are these bootstrap tags ? You shouldn't mix template tags (ie {% trans "text" %}) with functions (ie _("text")). The trans and blocktrans template tags should be used in your templates, the ugettext (aliased as _) to your python code.
So, for example instead of {{ _("Update") }} you should use {% trans "Update" %}.

Related

sphinx gettext inserts empty quotes "" in front of previously matching msg

Currently my worflow when I change things in the original file is this:
make gettext to update *.pot files
sphinx-intl update -p build/gettext -l fr to create *.po files out of it
However, this always results in the following behavior: Some longer messages in the *.po files are not correctly updated or to be more correct they are updated although they didn't change. sphinx-intl update will insert quotes "" in front of every paragraph that spans over multiple lines. Here's how that looks:
Before: (in some french *.po file):
msgid "Some longer paragraph text that spans multiple lines. This text was just"
"lying here and matched a sequence within the file before gettext inserted"
"unnecessary quotes on top."
msgstr "Un texte de paragraphe plus long qui s'étend sur plusieurs lignes. Ce texte se trouvait juste ici et correspondait à une séquence dans le fichier avant que gettext n'insère des guillemets inutiles par-dessus."
After:
msgid ""
"Some longer paragraph text that spans multiple lines. This text was just"
"lying here and matched a sequence within the file before gettext inserted"
"unnecessary quotes on top."
msgstr ""
"Un texte de paragraphe plus long qui s'étend sur plusieurs lignes "
"Ce texte se trouvait juste ici et correspondait à une séquence dans le "
"fichier avant que gettext n'insère des guillemets inutiles par-dessus."
This is extremely annoying as it will not match anymore with the text it is supposed to! Only when I remove the leading "" the texts will match again. I wondered if this happens because I tend write my translated msgstr as one line without intermitted quotes (what are they good for anyway?). After sphinx-intl update they are enclosed in quotes...
What is going on and how can I prevent this?

replacing html tag and its content using ruby gsub

I am trying to replace a <p>..</p> tag content in html content with empty string by doing the following.
string = \n <img alt=\"testing artice breaking news\" src=\"something.com" />\n <p>\n \tnew vision content for testing rss feeds\n </p>\n "
When I did
string.gsub!(/<p.*?>|<\/p>/, '')
It just replaced the <p> and </p> with empty string but the content remained. How can I remove both the tag and its content ?
Apparently, your regex does not match <p>...</p> (<p> and its content). Try this:
string.gsub!(/<p>.*<\/p>/, '')
test = '\n <img alt=\"testing artice breaking news\" src=\"something.com" />\n <p>\n \tnew vision content for testing rss feeds\n </p>\n "'
test.gsub(/<p>.*<\/p>/, '')
Return
"\\n <img alt=\\\"testing artice breaking news\\\" src=\\\"something.com\" />\\n \\n \""
Also, please consider #Tom Lord's comment, you can use Nokogiri to manipulate HTML.
First of all, consider using HTML parsers when parsing HTML, see How do I remove a node with Nokogiri?.
If you want to do it with a regex, you can use
string.gsub(/<p(?:\s[^>]*)?>.*?<\/p>/m, '')
See the Rubular regex demo. This will work with tags that cannot be nested. Details:
<p(?:\s[^>]*)?> - <p, and an optional sequence of a whitespace and zero or more chars other than > (as many as possible), and then >
.*? - due to /m, any zero or more chars as few as possible
<\/p> - </p> string.
If the tags can be nested, you still can use a regex:
tagname = "p"
rx = /<#{tagname}(?:\s[^>]*)?>(?:[^<]*(?:<(?!#{tagname}[\s>]|\/#{tagname}>)[^<]*)*|\g<0>)*<\/#{tagname}>/
p string.gsub(rx, '')
# => "\n <img alt=\"testing artice breaking news\" src=\"something.com\" />\n \n"
See the Rubular regex demo. Details:
<#{tagname} - < and tag name
(?:\s[^>]*)?> - an optional sequence of whitespace and then zero or more chars other than <
(?:[^<]*(?:<(?!#{tagname}[\s>]|\/#{tagname}>)[^<]*)*|\g<0>)* - zero or more occurrences of
(?:[^<]*(?:<(?!#{tagname}[\s>]|\/#{tagname}>)[^<]*)* - zero or more chars other than < and then zero or more sequences of < that is not followed with tag name + > or whitespace or / + tag name + > followed with zero or more chars other than < chars
|
\g<0> - the whole regex pattern recursed
<\/#{tagname}> - </ + tag name + >.
See a Ruby demo:
string = "\n <img alt=\"testing artice breaking news\" src=\"something.com\" />\n <p>\n \tnew vision content for testing rss feeds\n </p>\n"
p string.gsub(/<p(?:\s[^>]*)?>.*?<\/p>/m, '')
tagname = "p"
rx = /<#{tagname}(?:\s[^>]*)?>(?:[^<]*(?:<(?!#{tagname}[\s>]|\/#{tagname}>)[^<]*)*|\g<0>)*<\/#{tagname}>/m
p string.gsub(rx, '')```
# => "\n <img alt=\"testing artice breaking news\" src=\"something.com\" />\n \n"

Jekyll Categories, how to create Enum

How to create an ENUM / or something like jekyll, so that you have control of the categories.
---
layout : default
comments : true
title : 'Servindo sites estáticos com Jekyll'
subtitle : 'Entenda como o Jekyll funciona e como ele pode te ajudar a fazer websites estáticos.'
categories : [jekyll]
---
You can have a YAML list (['Apple', 'Orange', 'Strawberry', 'Mango']) or a space-separated string: as they explain in the jekyll Docs:
http://jekyllrb.com/docs/frontmatter/index.html#predefined-variables-for-posts

{} symbols are making my application crash

I've got this line in my cakePHP project:
<?= __('Doorzoek {0,number,#,###} foto\'s', $totalimg) ?>
Extracting this with the I18n Shell gives in the default.pot:
#: Template/Search/start.ctp:148
msgid "Doorzoek {0,number,#,###} foto's"
msgstr ""
Opening, translating and exporting to default.po with PoEdit makes this line:
#: Template/Search/start.ctp:148
msgid "Doorzoek {0,number,#,###} foto's"
msgstr "Search in {0, number, #, ###} pictures"
now, the {} symbols make my application crash.
What is the correct way to escape these so the phrase prints something like:
Search in 564,646 pictures
EDIT
so the problem is the space before the hashtags. Changing the line into
msgstr "Search in {0, number,#,###} pictures"
solved the problem.

How do I parse multiple strings from HTML using Nokogiri?

I need to parse this HTML code with Nokogiri, but save "Piso en Calle Antonio Pascual" in one variable and "Peñiscola" in another variable.
<h1 class="title g13_24">
Piso en Calle Antonio Pascual
<span class="title-extra-info">Peñíscola</span>
</h1>
require 'nokogiri'
doc = Nokogiri::HTML.parse(<<-HTML)
<h1 class="title g13_24">
Piso en Calle Antonio Pascual
<span class="title-extra-info">Peñíscola</span>
</h1>
HTML
h1 = doc.at_css('h1.title')
str1 = h1.children[0].text.strip
# => "Piso en Calle Antonio Pascual"
str2 = h1.at_css('.title-extra-info').text.strip
# => "Peñíscola"
But frankly, the Nokogiri documentation would have told you the same.

Resources