Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Customtranslations not adding custom translation


Go to End


4 Posts   1952 Views

Avatar
cyberde

Community Member, 10 Posts

22 June 2010 at 4:35am

Edited: 22/06/2010 5:13am

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!

Avatar
cyberde

Community Member, 10 Posts

22 June 2010 at 5:24am

Edited: 22/06/2010 5:24am

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;
	}

Avatar
mark_s

Community Member, 78 Posts

25 June 2010 at 8:31pm

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

Mark

Avatar
cyberde

Community Member, 10 Posts

26 June 2010 at 4:56am

No worries, glad i could help :)