0

I downloaded and enabled translations for my Drupal core and modules using these Drush commands:

drush dl l10n_update && drush en -y $_
drush language-add lt && drush language-enable $_
drush l10n-update-refresh
drush l10n-update

I got almost everything translated, and in "Administration » Configuration » Regional and language" I see that I have almost 60% of translations to Lithuanian.

However, not everything is translated. For example, harmony forum module thread reply;

http://prntscr.com/8rd9aw

    <ul class="post-links links--inline"><li class="show_replies first"><a href="/forumas/" id="post-1-show-replies" class="post-show-replies ajax-processed" data-thread-id="1" data-post-id="1">2 replies</a></li>
<li class="reply"><a href="/forumas/post/add?field_harmony_thread=1&amp;field_harmony_post_is_reply_to=1" id="post-1-reply" title="Reply directly to this post" class="reply-link" data-thread-id="1" data-post-id="1">Atsakyti</a></li>
<li class="reply_as_new_thread"><a href="/forumas/thread/add?field_harmony_thread_cont_from=1" id="post-1-reply-as-new" title="Create a new thread as a reply to this post" class="reply-link" data-thread-id="1" data-post-id="1">Reply as a new thread</a></li>
<li class="flag-harmony_likes last"><span><span class="flag-wrapper flag-harmony-likes flag-harmony-likes-1">
      <a href="/forumas/flag/flag/harmony_likes/1?destination=thread/1&amp;token=zOnI9qp9K92XqmzqfCM8P-0n7f_FEMQKzumwX_A4xb4" title="" class="flag flag-action flag-link-toggle flag-processed" rel="nofollow"><span class="count">(0)</span> <span class="text">Like</span></a><span class="flag-throbber">&nbsp;</span>
    </span>
</span></li>
</ul>

and user profile statistics

enter image description here

<div class="field field--name-field-harmony-thread-count field--type-number-integer field--label-above">
<div class="field__label">Thread count: </div>
<div class="field__items">
</div>
<div class="field field--name-field-harmony-post-count field--type-number-integer field--label-above">
<div class="field__label">Post count: </div>
<div class="field__items">
</div>

How can I edit these strings to be translated?

3 Answers 3

1

Here is a custom function I use in update hooks, to translate some missing translations, just in case you want to do this programmatically:

function translateString($source_string, $translated_string, $langcode) {
  $storage = \Drupal::service('locale.storage');
  $string = $storage->findString(array('source' => $source_string));
  if (is_null($string)) {
    $string = new SourceString();
    $string->setString($source_string);
    $string->setStorage($storage);
    $string->save();
  }
  // If exists, replace
  $translation = $storage->createTranslation(array(
    'lid' => $string->lid,
    'language' => $langcode,
    'translation' => $translated_string,
  ))->save();
}

To implement it you can do the following (i.e. in a update hook):

function my_module_update_8000() {
  translateString(
    'The original String',
    'My translated String to german thats why the next parameter is "de"',
    'de'
  );
}
0

Identify what template it is using with Themer. Override it and use t() function to wrap those strings needed to be translated.

0
0

My solution:

I tried Devel Themer module as suggested, but I was not able to find function source to copy and change it for my needs. After unsuccessfull tries to add my translations via template.php and by creating custom tpl.php in templates folder of my theme, I decided to use this method:

! Before proceeding make sure that you have your non-english language downloaded and enabled as default in "Administration » Configuration » Regional and language » List"


1. Download and enable:

2. In

Administration » Configuration » Regional and language » Multilingual settings » Strings choose "English" as source language.

3. In

Administration » Configuration » Regional and language » Translate interface » Translate search for your string, which you want to translate and limit search to Views, Fields or Blocks.

4. Translate

all occurrences of your untranslated strings.

5. Go to

Administration » Configuration » Regional and language » Translate interface » Strings , choose all text groups and click "Refresh strings" to clean up translations, which can overlap.


That's it!

P.S. You can also use Administration » Configuration » Regional and language » Translate interface » Extract to choose any module or theme, extract untranslated strings to .po file and then Import that file back when translated. This potx module scans for strings wrapped with t() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.