Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
gettext.js49 linesDownload Raw Back to js
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9 10define(['translations'], function (translations) {11 12  /***13   * This method behaves as a drop-in replacement for flask translation rendering.14   * It uses the same translation file under the hood and uses flask to determine the language.15   * It is slightly tweaked to work like sprintf16   * ex. translate("some %s text", "cool")17   *18   * @param {String} text19   */20  return function gettext(text) {21 22    let rawTranslation = translations[text] ? translations[text] : text;23 24    if(arguments.length == 1) {25      return rawTranslation;26    }27 28    try {29      let replaceArgs = arguments;30      return rawTranslation.split('%s')31        .map(function(w, i) {32          if(i > 0) {33            if(i < replaceArgs.length) {34              return [replaceArgs[i], w].join('');35            } else {36              return ['%s', w].join('');37            }38          } else {39            return w;40          }41        })42        .join('');43    } catch(e) {44      console.error(e);45      return rawTranslation;46    }47  };48});49 
codekingpro/portable-devtools · Team Ai