How to use transliteration - 10 common examples

To help you get started, we’ve selected a few transliteration examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dragory / modmailbot / src / threads.js View on Github external
return jsonDb.get('threads', []).then(threads => {
    const thread = threads.find(t => t.userId === user.id);
    if (thread) return thread;

    // If we didn't find an existing modmail thread, attempt creating one
    if (! allowCreate) return null;

    // Channel names are particularly picky about what characters they allow...
    let cleanName = transliterate.slugify(user.username);
    if (cleanName === '') cleanName = 'unknown';
    cleanName = cleanName.slice(0, 95); // Make sure the discrim fits

    const channelName = `${cleanName}-${user.discriminator}`;

    if (originalMessage && originalMessage.cleanContent && config.ignoreAccidentalThreads) {
      const cleaned = originalMessage.cleanContent.replace(/[^a-z\s]/gi, '').toLowerCase().trim();
      if (accidentalThreadMessages.includes(cleaned)) {
        console.log('[NOTE] Skipping thread creation for message:', originalMessage.cleanContent);
        return null;
      }
    }

    console.log(`[NOTE] Creating new thread channel ${channelName}`);
    return getUtils().getInboxGuild().createChannel(`${channelName}`)
      .then(channel => {
github Dragory / ZeppelinBot / backend / src / plugins / Automod.ts View on Github external
protected evaluateMatchRegexTrigger(trigger: TMatchRegexTrigger, str: string): null | string {
    if (trigger.normalize) {
      str = transliterate(str);
    }

    // TODO: Time limit regexes
    for (const pattern of trigger.patterns) {
      const regex = new RegExp(pattern, trigger.case_sensitive ? "" : "i");
      const test = regex.test(str);
      if (test) return regex.source;
    }

    return null;
  }
github Dragory / modmailbot / src / modules / move.js View on Github external
commands.addInboxThreadCommand('move', '', async (msg, args, thread) => {
    const searchStr = args.category;
    const normalizedSearchStr = transliterate.slugify(searchStr);

    const categories = msg.channel.guild.channels.filter(c => {
      // Filter to categories that are not the thread's current parent category
      return (c instanceof Eris.CategoryChannel) && (c.id !== msg.channel.parentID);
    });

    if (categories.length === 0) return;

    // See if any category name contains a part of the search string
    const containsRankings = categories.map(cat => {
      const normalizedCatName = transliterate.slugify(cat.name);

      let i = 0;
      do {
        if (! normalizedCatName.includes(normalizedSearchStr.slice(0, i + 1))) break;
        i++;
github retorquere / zotero-better-bibtex / content / key-manager / formatter.ts View on Github external
if (mode === 'japanese') mode = null
    const replace = {
      german: {
        '\u00E4': 'ae', // tslint:disable-line:object-literal-key-quotes
        '\u00F6': 'oe', // tslint:disable-line:object-literal-key-quotes
        '\u00FC': 'ue', // tslint:disable-line:object-literal-key-quotes
        '\u00C4': 'Ae', // tslint:disable-line:object-literal-key-quotes
        '\u00D6': 'Oe', // tslint:disable-line:object-literal-key-quotes
        '\u00DC': 'Ue', // tslint:disable-line:object-literal-key-quotes
      },
    }[mode]
    if (mode && !replace) throw new Error(`Unsupported fold mode "${mode}"`)

    if (kuroshiro.enabled) str = kuroshiro.convert(str, {to: 'romaji'})
    str = transliterate(str || '', {
      unknown: '\uFFFD', // unicode replacement char
      replace,
    })

    str = fold2ascii(str)

    return str
  }
  private clean(str) {
github fuuka1 / QiNA / src / runner / MainConnector.js View on Github external
err: '未配置'
        }
        event.sender.send('qina', returnMsg) 
        return false;
      }
  
      if (val.Access == null || val.Bucket == null || val.Domain == null || val.Secret == null) {
        returnMsg = {
          state: false,
          err: '配置不全'
        }
        event.sender.send('qina', returnMsg)
        return false;
      }
  
      var key = transliteration.slugify(arg.Name) + '(' + moment().format() + ')' + path.extname(arg.Name);
      var filePath = path.normalize(arg.Path);
  
      var client = qn.create({
        accessKey: val.Access,
        secretKey: val.Secret,
        bucket: val.Bucket,
        origin: val.Domain,
      });
  
      console.log('qn 开始上传');
      client.uploadFile(filePath, {
        key: key
      }, function(err, ret) {
        console.log(ret);
  
        if (!err) {
github quanglam2807 / translatium / src / helpers / translate-text.js View on Github external
.then((response) => {
        const langs = response.lang.split('-');

        output.inputLang = langs[0];
        output.outputLang = outputLang;
        output.inputText = inputText;
        output.outputText = outputLang === 'zh-TW' ? mConv.phrase('s2t', response.text[0]) : response.text[0];

        if (outputLang.startsWith('zh')) {
          const outputRoman = tr(response.text[0]);
          if (outputRoman !== response.text[0]) {
            output.outputRoman = outputRoman;
          }
        }

        if (inputLang === 'zh') {
          const inputRoman = tr(inputText);
          if (inputRoman !== inputText) {
            output.inputRoman = inputRoman;
          }
        }

        if (output.outputRoman === output.outputText) output.outputRoman = undefined;
      }),
  );
github quanglam2807 / translatium / src / helpers / translate-text.js View on Github external
const langs = response.lang.split('-');

        output.inputLang = langs[0];
        output.outputLang = outputLang;
        output.inputText = inputText;
        output.outputText = outputLang === 'zh-TW' ? mConv.phrase('s2t', response.text[0]) : response.text[0];

        if (outputLang.startsWith('zh')) {
          const outputRoman = tr(response.text[0]);
          if (outputRoman !== response.text[0]) {
            output.outputRoman = outputRoman;
          }
        }

        if (inputLang === 'zh') {
          const inputRoman = tr(inputText);
          if (inputRoman !== inputText) {
            output.inputRoman = inputRoman;
          }
        }

        if (output.outputRoman === output.outputText) output.outputRoman = undefined;
      }),
  );
github reactioncommerce / reaction / imports / plugins / core / core / server / Reaction / getSlug.js View on Github external
export default function getSlug(slugString) {
  return (typeof slugString === "string" && slugify(slugString)) || "";
}
github koahubjs / koahub-simple-cms / app / controller / admin / article.controller.js View on Github external
async add() {

        if (this.isPost()) {

            const article = this.post;

            article.pinyin = slugify(article.title);

            await this.model('article').add(article);

            this.json('/admin/article/index', '保存成功');
        } else {

            if (this.query.id) {
                var article = await this.model('article', {withRelated: ['file']}).find({id: this.query.id});
                await this.render('article_add', {article: article});
            } else {
                await this.render('article_add');
            }
        }
    }
}
github museui / muse-ui / docs / build / gen-indices.js View on Github external
indices = indices.concat(matches.map(match => {
          const isComponent = match[0].indexOf('##') < 0;
          const title = match[0].replace(/#{1,4}/, '').trim();
          const index = { component: getComponentName(component), title };
          index.ranking = isComponent ? 2 : 1;
          index.anchor = slugify(title);
          index.content = (match[1] || title).replace(/<[^>]+>/g, '');
          return index;
        }));
      });

transliteration

Unicode to ACSII transliteration / slugify module for node.js, browser, Web Worker, ReactNative and CLI.

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis