Check that translation is valid: entry: array [key, translation]  corresponding to a single string from <locale>.json - messages with placeholders have the same number of placeholders - messages must not have newlines embedded
179826
function (entry) {
    const re = /(%\d)/g;
    const [key, translation] = entry;
    const enMatch = en[key].match(re);
    const tMatch = translation.match(re);
    const enCount = enMatch ? enMatch.length : 0;
    const tCount = tMatch ? tMatch.length : 0;
    assert.strictEqual(tCount, enCount, `${key}:${en[key]} - "${translation}" placeholder mismatch`);
    if (enCount > 0) {

      assert.notStrictEqual(tMatch, null, `${key} is missing a placeholder: ${translation}`);
      assert.strictEqual(
          tMatch.sort().toString(),
          enMatch.sort().toString(),
          `${key} is missing or has duplicate placeholders: ${translation}`
      );
    }
    assert.strictEqual(translation.match(/[\n]/), null, `${key} contains a newline character ${translation}`);
}
1081618
private String getLocalizationMessages(CmsMessages messages) {

        JSONObject result = new JSONObject();
        try {
            result.put("search", messages.key(Messages.GUI_CODEMIRROR_LANG_SEARCH_0));
            result.put("hint", messages.key(Messages.GUI_CODEMIRROR_LANG_HINT_0));
            result.put("replace", messages.key(Messages.GUI_CODEMIRROR_LANG_REPLACE_0));
            result.put("replacewith", messages.key(Messages.GUI_CODEMIRROR_LANG_REPLACE_WITH_0));
            result.put("replaceconfirm", messages.key(Messages.GUI_CODEMIRROR_LANG_REPLACE_CONFIRM_0));
            result.put("replaceyes", messages.key(Messages.GUI_CODEMIRROR_LANG_REPLACE_YES_0));
            result.put("replaceno", messages.key(Messages.GUI_CODEMIRROR_LANG_RELACE_NO_0));
            result.put("replacestop", messages.key(Messages.GUI_CODEMIRROR_LANG_REPLACE_STOP_0));

            result.put("fontsize", messages.key(Messages.GUI_CODEMIRROR_LANG_FONT_SIZE_0));
        } catch (org.opencms.json.JSONException e) {
            // should never happen
        }
        return result.toString();
    }
755477
function(english, language) {
    if (typeof translations[english] !== 'undefined' && typeof translations[english][language] !== 'undefined') {
      return translations[english][language];
    } else {
      return english;
    }
  }
1007242
def _check_valid_translation(self, translation):
        
        if not isinstance(translation, np.ndarray) or not np.issubdtype(translation.dtype, np.number):
            raise ValueError('Translation must be specified as numeric numpy array')

        t = translation.squeeze()
        if len(t.shape) != 1 or t.shape[0] != 3:
            raise ValueError('Translation must be specified as a 3-vector, 3x1 ndarray, or 1x3 ndarray')
148035
def translation_for(locale)
      success = true
      tries ||= 3
      translation = self.translations.detect{ |t| t.locale == locale }
      return translation if translation
      return nil if self.new_record
      request = Net::HTTP::Get.new("/api/projects/#{Connection.api_key}/strings/#{self.id}/locales/#{locale}/translations.yaml")
      WebTranslateIt::Util.add_fields(request)
      begin
        response = Util.handle_response(Connection.http_connection.request(request), true, true)
        hash = YAML.load(response)
        return nil if hash.empty?
        translation = WebTranslateIt::Translation.new(hash)
        return translation
        
      rescue Timeout::Error
        puts "Request timeout. Will retry in 5 seconds."
        if (tries -= 1) > 0
          sleep(5)
          retry
        else
          success = false
        end
      end
      success
    end
1061635
def validate(self, value: LocalizedValue, *_):
        

        if self.null:
            return

        for lang in self.required:
            lang_val = getattr(value, settings.LANGUAGE_CODE)

            if lang_val is None:
                raise IntegrityError('null value in column "%s.%s" violates '
                                     'not-null constraint' % (self.name, lang))
645527
public String getMessage(String key, Locale locale, Object[] parameters)
	{
		if (null == locale)
		{
			return getMessage(key, parameters);
		}
		if (null == parameters)
		{
			return getMessage(key, locale);
		}
		if (null != key)
		{
			MessageFormat _messageFormat = new MessageFormat(getMessage(key, locale));
			return _messageFormat.format(parameters);
		}

		return null;
	}
980647
function translateInLanguageFilter(key, locale) {
    for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
      args[_key - 2] = arguments[_key];
    }

    return translateInLanguage.apply(void 0, [locale, key].concat(args));
  }
1345378
def _validate_translation(self, aligned_prot, aligned_nucl):
        
        codons = [''.join(i) for i in batch(str(aligned_nucl), 3)]
        for codon, aa in zip(codons, str(aligned_prot)):
            # Check gaps
            if codon == '---' and aa == '-':
                continue

            try:
                trans = self.translation_table.forward_table[codon]
                if not trans == aa:
                    raise ValueError("Codon {0} translates to {1}, not {2}".format(
                        codon, trans, aa))
            except (KeyError, CodonTable.TranslationError):
                if aa != 'X':
                    if self.unknown_action == 'fail':
                        raise ValueError("Unknown codon: {0} mapped to {1}".format(
                            codon, aa))
                    elif self.unknown_action == 'warn':
                        logging.warn('Cannot verify that unknown codon %s '
                                     'maps to %s', codon, aa)
        return True
1179817
def validate(args):
    
    if args.format not in FORMATTERS:
        print(
            "Subtitle format not supported. "
            "Run with --list-formats to see all supported formats."
        )
        return False

    if args.src_language not in LANGUAGE_CODES.keys():
        print(
            "Source language not supported. "
            "Run with --list-languages to see all supported languages."
        )
        return False

    if args.dst_language not in LANGUAGE_CODES.keys():
        print(
            "Destination language not supported. "
            "Run with --list-languages to see all supported languages."
        )
        return False

    if not args.source_path:
        print("Error: You need to specify a source path.")
        return False

    return True
95612
def accept
      @translation = Translation.find(params[:translation_id])
      @translation_already_accepted = @translation.key.accepted_in? session[:lang_to]
      @translation.accept
      respond_to do |format|
        format.js
      end
    end
795364
function ( options ) {
    // Some minimal defaults
    this.defaults = {
      "locale_data" : {
        "messages" : {
          "" : {
            "domain"       : "messages",
            "lang"         : "en",
            "plural_forms" : "nplurals=2; plural=(n != 1);"
          }
          // There are no default keys, though
        }
      },
      // The default domain if one is missing
      "domain" : "messages",
      // enable debug mode to log untranslated strings to the console
      "debug" : false
    };

    // Mix in the sent options with the default options
    this.options = _.extend( {}, this.defaults, options );
    this.textdomain( this.options.domain );

    if ( options.domain && ! this.options.locale_data[ this.options.domain ] ) {
      throw new Error('Text domain set to non-existent domain: `' + options.domain + '`');
    }
  }
1343959
def translate_with_annotation(key, options={})
      # default to an empty scope
      scope = []

      # In the case of a missing translation, fall back to letting TranslationHelper
      # put in span tag for a translation_missing.
      begin
        AnnoTranslate.translate_with_annotation(scope, @virtual_path, key, options.merge({:raise => true}))
      rescue AnnoTranslate::AnnoTranslateError, I18n::MissingTranslationData => exc
        # Call the original translate method
        str = translate_without_annotation(key, options)

        # View helper adds the translation missing span like:
        # In strict mode, do not allow TranslationHelper to add "translation missing" span like:
        # <span class="translation_missing">en, missing_string</span>
        if str =~ /span class\=\"translation_missing\"/
          # In strict mode, do not allow TranslationHelper to add "translation missing"
          raise if AnnoTranslate.strict_mode?

          # Invoke callback if it is defined
          AnnoTranslate.missing_translation_callback(exc, key, options)
        end

        str
      end
    end
254565
private function getTranslation($message, array $placeholders)
    {
        if ($this->translator->has($message)) {
            $message = $this->translator->get($message, $placeholders);
        }

        return $message;
    }
240266
private String messageImportInvalidFormat(Locale locale) {

        return Messages.get().getBundle(locale).key(Messages.ERR_ALIAS_IMPORT_BAD_FORMAT_0);
    }
1060276
def parse_value(v, locale)
      new_value = nil
      case v
        when Symbol then
          lk = @localization_key_object_cache[v.to_s] || \
            Lit::LocalizationKey.where(localization_key: v.to_s).first
          if lk
            loca = Lit::Localization.active.where(locale_id: locale.id).
                        where(localization_key_id: lk.id).first
            new_value = loca.translation if loca && loca.translation.present?
          end
        when String then
          new_value = v
        when Hash then
          new_value = nil
        when Proc then
          new_value = nil # was v.call - requires more love
        else
          new_value = v.to_s
      end
      new_value
    end
778563
def key_exists?(key, locale)
      I18n.locale = locale
      I18n.translate(key, raise: true)
      return true
    rescue I18n::MissingInterpolationArgument
      return true
    rescue I18n::MissingTranslationData
      return false
    end