acrylamid icon indicating copy to clipboard operation
acrylamid copied to clipboard

'tagged as' and 'and' could be localizated in theme/entry.html

Open ghost opened this issue 11 years ago • 22 comments

Just a minor bug: in theme/entry.html subsitute 'tagged as' and 'and' with localizated version:

    % if 'tag' in env.views and entry.tags:
        <p>tagged as
            % for link in tagify(entry.tags):
                <a href="${ env.path + link.href }" rel="tag">${ link.title }</a>
                % if loop.reverse_index > 1:
                ,
                % elif loop.reverse_index == 1:
                i
                % endif
            % endfor
        </p>
    % elif not entry.draft:
        <p>untagged</p>
    % endif

ghost avatar May 31 '13 15:05 ghost

Same with 'written by {{author}}' and in articles page title.

ghost avatar Jun 02 '13 10:06 ghost

How can I manually put a localizated string? That is if 'foo' is a string, how can I localizated 'foo'? Is there any function like 'localizate('foo')' that simply reads the locale and read the translation of 'foo'?

ghost avatar Jun 02 '13 10:06 ghost

Hi @xavimat unfortunately not. I do plan to add a function like i18n('bar') in the next release (using some default translations from the Nikola project).

I18n templates has been on my todo list for several months now :(

posativ avatar Jun 02 '13 10:06 posativ

@posativ, a pain, really pain. Please set is as priority bug ;-)

ghost avatar Jun 03 '13 14:06 ghost

Hi @xavimat, can you give me some hints on the expected usage? Do you use the translation view?

posativ avatar Jun 03 '13 15:06 posativ

@posativ: Translation view? What is this?

My expected usage is to "translate" the template theme/entry.html. For example, in that file, there is a string:

'written by {{author}}' 

This is not localized. I want to have "i18n('written by {0}'.format({{author}}) for display this message depending of LANG appeared in conf.py. So if the page has translation to several languages, the users see localizated message...

If not, manual intervention is required if lang==foo, then ....

ghost avatar Jun 03 '13 19:06 ghost

By the other hand, don't forget to right-to-left languages.

ghost avatar Jun 03 '13 19:06 ghost

'continue' in index.html nope.

ghost avatar Jun 07 '13 12:06 ghost

You can set SUMMARIZE_LINK to a custom value.

posativ avatar Jun 07 '13 13:06 posativ

Thanks

ghost avatar Jun 07 '13 15:06 ghost

But I receive error:

Traceback (most recent call last): File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 2822, in working_set.require(requires) File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 696, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 598, in resolve raise VersionConflict(dist,req) # XXX put more info here pkg_resources.VersionConflict: (Jinja2 2.7 (/home/xan/.local/lib/python3.3/site-packages), Requirement.parse('Jinja2==2.6'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/xan//.local/bin/acrylamid", line 5, in from pkg_resources import load_entry_point File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 2826, in parse_requirements(requires), Environment() File "/usr/lib/python3.3/site-packages/pkg_resources.py", line 594, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: Jinja2==2.6 x

ghost avatar Jun 07 '13 15:06 ghost

Because, I recently updated Jinja

ghost avatar Jun 07 '13 15:06 ghost

Yep. Jinja 2.7 does not work with Acrylamid anyways. Either use the master (of both Jinja2 and Acrylamid, I do not recomend that) or stay with Jinja 2.6 (ported by hand btw).

posativ avatar Jun 07 '13 15:06 posativ

I reinstall jinja2.6 but I get now this issue:

xan@gerret:/home/xan/proves/github/[email protected]/cepasud$ acrylamid co Traceback (most recent call last): File "/home/xan//.local/bin/acrylamid", line 9, in load_entry_point('acrylamid==0.7.7.dev0', 'console_scripts', 'acrylamid')() File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/init.py", line 179, in Acryl commands.compile(conf, env) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/commands.py", line 219, in compile for buf, path in v.generate(conf, env, data): File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/views/index.py", line 63, in generate items_per_page=ipp, num_entries=len(entrylist), route=route)) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/templates/mako.py", line 125, in render self.template.render_context(ctx) File "/usr/lib/python3.3/site-packages/mako/template.py", line 466, in render_context **kwargs) File "/usr/lib/python3.3/site-packages/mako/runtime.py", line 815, in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File "/usr/lib/python3.3/site-packages/mako/runtime.py", line 841, in exec_template callable(context, _args, *_kwargs) File "/home/xan/proves/github/[email protected]/cepasud/.cache/cache_base.html.py", line 77, in render_body context['self'].content(**pageargs) File "/home/xan/proves/github/[email protected]/cepasud/.cache/cache_main.html.py", line 97, in render_content *M_writer(str(block_entry(entry))) File "/home/xan/proves/github/[email protected]/cepasud/.cache/cache_entry.html.py", line 49, in render_block_entry __M_writer(entry.content ) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/readers.py", line 442, in content res = f.transform(res, self, f.args) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/filters/__init.py", line 119, in cls, dct.get('transform', bases[0].transform))(cls, x, y, *z) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/filters/summarize.py", line 126, in transform content, maxwords, self.env.path+entry.permalink, options).result) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/filters/summarize.py", line 22, in init HTMLParser.init(self, text) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/lib/html.py", line 70, in init self.feed(html) File "/usr/lib/python3.3/html/parser.py", line 145, in feed self.goahead(0) File "/usr/lib/python3.3/html/parser.py", line 191, in goahead k = self.parse_endtag(i) File "/usr/lib/python3.3/html/parser.py", line 458, in parse_endtag self.handle_endtag(elem.lower()) File "/home/xan/.local/lib/python3.3/site-packages/acrylamid/filters/summarize.py", line 65, in handle_endtag self.result.append(self.options['link'] % self.href) TypeError: not all arguments converted during string formatting

ghost avatar Jun 07 '13 15:06 ghost

Please refer to the documentation: http://posativ.org/acrylamid/filters.html#summarize :

[...] This string must contain %s where the link location will be inserted.

posativ avatar Jun 07 '13 15:06 posativ

OK.

ghost avatar Jun 08 '13 21:06 ghost

Hi @xavimat, I experimented a bit with i18n support in templates and that's my progress so far:

  • [x] imported nikola's i18n messages
  • [x] Jinja2's i18n extensions works fine when you write {% trans %}Archive{% endtrans %} in your templates and your conf.py says LANG = 'es' for example.
  • [x] translated posts currently use post's language
  • [ ] support for custom messages not included, e.g. "tagged as" is not available in Nikola.

posativ avatar Jun 15 '13 14:06 posativ

OK. Thanks for the improvements. By now, I will not updated acrylamid, but in the future, I will...

ghost avatar Jun 19 '13 18:06 ghost

I18N support is nearly finished, but I have no idea for the last missing point: custom messages. There's probably no option to use custom messages (unless you write the .po, compile to .mo and then merge both catalogs).

Another option would be a custom implementation of the gettext interface to provide easier integration of custom messages, such as:

# $ cat messages/custom.py
["english text", "spanish text", [optional third etc.],
["next text", ...]

whereas per convention the first item per list is the default language (or english?). Because I don't like the repetition of something like:

# messages/de.py
{
"Hello": "Hallo",
"World": "Welt"
}

# messages/es.py
{
"Hello": "Hola",
"World": "Mundo"
}

So, what do you prefer?

posativ avatar Jun 23 '13 14:06 posativ

Why not {"Hello": {'en': 'Hello', 'es': 'Hola', ...}, "Bye": {'en': 'Bye', 'es': 'Adiós', ...}}?

ghost avatar Jun 23 '13 16:06 ghost

``Yes, a good idea... could be used as a fallback to a preset of messages. So, I'm fine with custom messages in the conf.py via:

MESSAGES = {
  "Hello": {"en": "Hello", "es": "Hola"},
  ...
}

EDIT: there's probably no need for "Hello": {"en": "Hello"} (provide a "translation" for the english identifier) ... but only "Hello": {"es": "Hola"}.

posativ avatar Jun 23 '13 22:06 posativ

Proud if you think it's good idea. I include "Hello": {"en": "Hello"} plus DEFAULT_LANG='en' (or whatever). Please, think not all content is english centric.

ghost avatar Jun 24 '13 10:06 ghost