Code Monkey home page Code Monkey logo

confuse's Introduction

Confuse Build Status

Convert ascii strings to commonly confused unicode characters

Purpose

Those familiar with xgettext know that in order to provide translations it is necessary to tag strings requiring translation with a function, normally gettext(...) or the commonly used alias _(...).

While attempting to confirm full i18n support for an application it became necessary to find all strings that were missing the proper translation functions. It was proposed that a dummy language be created that provides a translation for every entry in a PO file in such a way that the msgid and msgstr be mostly similar but still discernible.

The purpose of Confuse is to take a string with all ascii characters and return a lookalike string using unicode characters. The goal is for the string to remain readable but altered enough that it is clearly visible. For example:

this is a test -> ŧħïş ïş ã ŧëşŧ

Usage

>>> from confuse import confuse
>>> confuse('this is a string')
u'\u0167\u0127\xef\u015f \xef\u015f \xe3 \u015f\u0167\u0155\xef\xf1\u011f'
>>> confuse('this is a string').encode('utf-8')
'\xc5\xa7\xc4\xa7\xc3\xaf\xc5\x9f \xc3\xaf\xc5\x9f \xc3\xa3 \xc5\x9f\xc5\xa7\xc5\x95\xc3\xaf\xc3\xb1\xc4\x9f'
>>> print confuse('this is a string').encode('utf-8')
ŧħïş ïş ã şŧŕïñğ

Confuse tries to be smart about skipping things that should not be altered. Therefore, it tries to recognize various python string formatters as well as anything contained in an HTML tag.

>>> foo = 'Hi, my name is %(name)s'
>>> print confuse(foo)
Ĥï❟ ṁý ñãṁë ïş %(name)s
>>> bar = 'I like {} and {}'
>>> print confuse(bar)
Į ļïķë {} ãñᶁ {}
>>> baz = '<a href="index.html">This is a link to %s</a>'
>>> print confuse(baz)
<a href="index.html">Ŧħïş ïş ã ļïñķ ŧð %s</a>

Why Confuse?

The Unicode Consortium has a utility to generate a set of confusable characters (a.k.a. confusables) for a given input. The purpose of this program is to generate something similar.

confuse's People

Contributors

kyokley avatar

Stargazers

Joshua Shields avatar

Watchers

James Cloos avatar Joshua Shields avatar  avatar  avatar

confuse's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.