This recipe shows a routine and a driver program that lets you "i18nify" any word, similar to how the word "internationalization" is shortened to "i18n", and "localization" to "l10n".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from __future__ import print_function
'''
Utility to "i18nify" any word given as argument.
You Heard It Here First (TM):
"i18nify" signifies making a numeronym of the given word, in the
same manner that "i18n" is a numeronym for "internationalization"
- because there are 18 letters between the starting "i" and the
ending "n". Another example is "l10n" for "localization".
Also see a16z.
Author: Vasudev Ram
Copyright 2016 Vasudev Ram - https://vasudevram.github.io
'''
def i18nify(word):
# If word is too short, don't bother, return as is.
if len(word) < 4:
return word
# Return (the first letter) plus (the string form of the
# number of intervening letters) plus (the last letter).
return word[0] + str(len(word) - 2) + word[-1]
def get_words():
for words in [ \
['a', 'bc', 'def', 'ghij', 'klmno', 'pqrstu', 'vwxyz'], \
['the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', \
'lazy', 'dog'], \
['all', 'that', 'glitters', 'is', 'not', 'gold'], \
['often', 'have', 'you', 'heard', 'that', 'told'], \
['jack', 'and', 'jill', 'went', 'up', 'the', 'hill', \
'to', 'fetch', 'a', 'pail', 'of', 'water'],
]:
yield words
def test_i18nify(words):
print("\n")
print(' '.join(words))
print(' '.join([i18nify(word) for word in words]))
def main():
for words in get_words():
test_i18nify(words)
print
if __name__ == "__main__":
main()
|
More details and example output here:
http://jugad2.blogspot.in/2016/05/i18nify-any-word-with-this-python.html