public function onBeforeWrite()
    {
        if (!isset(self::$localizedFields[$this->ownerBaseClass])) {
            return;
        }

        $fields = self::$localizedFields[$this->ownerBaseClass];
        foreach ($fields as $field => $localized) {
            foreach (self::get_target_locales() as $locale) {
                $fieldName = self::localized_field($field, $locale);
                if ($this->owner->isChanged($fieldName, 2) && !$this->canTranslate(null, $locale)) {
                    throw new PermissionFailureException(
                        "You're not allowed to edit the locale '$locale' for this object");
                }
            }
        }
    }