Problem/Motivation

How do we translate instructions in crossword-instructions.tpl.php?

Proposed resolution

Implement https://www.drupal.org/docs/theming-drupal/twig-in-drupal/create-custom-...

Whether accepted, I will post a patch for this

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

afagioli created an issue. See original summary.

afagioli’s picture

Issue tags: +internationalization
danflanagan8’s picture

The current way to customize the instructions is to put a crossword-instructions.html.twig in your site's theme and then make the text whatever you want.

That's clumsy though because it assumes the site has a custom theme, which isn't always the case.

One option would be to wrap all the bits of text in crossword-instructions.html.twig in {% trans %} tags, which would allow translation through the UI. That might be good enough?

I'm not too familiar with translation and internationalization from the site-building perspective, so your insight would be helpful here.

afagioli’s picture

Issue summary: View changes

Text to be translated in crossword-instructions.tpl.php is so specific. No need now to face the "context" element in translation.
Thus, the easiest {{ 'Active Square'|t }} seems to be enough.

Patch on the way...

afagioli’s picture

danflanagan8’s picture

Status: Active » Needs work
+++ b/templates/crossword-instructions.html.twig
@@ -1,67 +1,66 @@
       <div>
-        <dt>Arrow keys:</dt>
-        <dd>Move active square.</dd>
+        <dt>:</dt>
+        <dd>{{ 'Move active square'|t }}.</dd>
       </div>

Looks like you missed "Arrow Keys"

Other than that it looks good when I test it out. If you make that update I'll commit.

I have a question about a comment you made though:

No need now to face the "context" element in translation.

I don't see any difference between using |t and using {% trans %}. Could you clarify?

danflanagan8’s picture

Also, would you be able to provide an Italian translation for the instructions? I'm new to this, so I'm not sure if that goes in the module or if it goes to localize.drupal.org. But that would be really cool.

afagioli’s picture

Improving previous patch with missing string.
Thanks for pointing that out.

afagioli’s picture

I don't see any difference between using |t and using {% trans %}. Could you clarify?

Sure thing.
Following https://www.drupal.org/docs/8/api/translation-api/overview > Translation in Twig templates,
|t comes handy most of times while I can use {% trans %} for more complex cases. Let's say we need to add the string "down" in the crossword-instructions.html.twig
As translator, the "down" word is ambiguous. With {% trans %} I can add a "crossword" context to this string. This way I will have the default "down" string ("giù" in italian) and the crossword "down" ("vertical" in italian).

Real case at https://www.drupal.org/project/crossword/issues/3232223#comment-14214443

I'm not sure this is clear. Feel free to ask for further clarification

afagioli’s picture

Assigned: afagioli » Unassigned

danflanagan8’s picture

Status: Needs work » Fixed

Committed patch from #8. Thanks for the patch and for teaching me about translation, @afagioli.

afagioli’s picture

#7 in very useful also.

From Drupal 8, translation can be easily added from https://localize.drupal.org/translate/languages/it/translate?page=2&proj... , which is pretty cool.

From my understading we will be able to translation new internationalised strings with new the module release.

Should we maybe open a specific issue as reminder?

danflanagan8’s picture

Thanks for the link, @afagioli. I've opened a new ticket for discussion and planning if you're interested: #3232748: Translation and Internationalization.

afagioli’s picture

Following.
Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.