Jump to:

10848 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Customtranslations not adding custom translation

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1126 Views
  • cyberde
    Avatar
    Community Member
    10 Posts

    Customtranslations not adding custom translation Link to this post

    Hi,

    I've just installed Customtranslations and I was trying to add a custom translation using the 'Create Custom Language Translation'-button but when I click the 'Add'-button, nothing happens.

    Although clicking the plus-sign near an already existing translation, editing the values to match the same values entered when I clicked the 'Create Custom Language Translation'-button, and then clicking the 'Add'-button works. Is this suppost to work this way or is the 'Create Custom Language Translation'-function just broken?

    Cheers!

  • cyberde
    Avatar
    Community Member
    10 Posts

    Re: Customtranslations not adding custom translation Link to this post

    Okay I've found the problem and I fixed it.

    The problem occurs in the CustomTranslationValidator class where it checks for 'OriginalTranslation'. But that value doesn't exist when creating clicking the 'Create Custom Language Translation'-button.
    Since the whole function depends on that value it will never return true nor will it display.

    Here's the edited method:

       function php($data) {
    // Set value to true unless set otherwise below
    $valid = true;

          if (!parent::php($data)) return false; // required fields failed.

    // do we have a OriginalTranslatio value? If not, why continue validating? ;)
    if (isset($data['OriginalTranslation'])) {
          $origTokens = $this->getTokens($data['OriginalTranslation']);
          $newTokens = $this->getTokens($data['Translation']);

          // determine if they are the same
          $valid = count($origTokens) == count($newTokens);

          if ($valid && count($origTokens) > 0) {
             // Counts are the same, so iterate over both arrays and ensure they are compatible.
             for ($i = 0; $i < count($origTokens); $i++) {
                // @todo This requires an exact match. For example, %10d and %d won't match, but should.
                if ($origTokens[$i] != $newTokens[$i]) $valid = false;
             }
          }
    }

          if (!$valid) {
             $this->validationError(
                'Translation',
                _t('Form.FIELDSIGNATUREMISMATCH', "The value substitution tokens in the new translation must match the tokens in the original translation string"),
                "invalid"
             );
          }

          return $valid;
       }

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Customtranslations not adding custom translation Link to this post

    Hi. Thanks for that. I will have a look at integrating that back in

    Mark

  • cyberde
    Avatar
    Community Member
    10 Posts

    Re: Customtranslations not adding custom translation Link to this post

    No worries, glad i could help

    1126 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.