Change Your Website's Language With Swedish Chef's Accent

Does anyone know the Swedish Chef? I learned it also a few weeks ago. He is one of the characters of The Muppets. Watch this if you don't know the Swedish Chef. There is one plugin that transfers the website's content for you to Swedish Chef's accent. This is called Bork Bork! plugin. I will tell you how i wrote its code in Python.

Firstly, the system works like this, there is a one general rule that says for example "a should became e". However the system is not that simple. There is a few exceptional rules too. For instance, for latter 'a' exceptions are, "if a is singular it should remain a" and "final e should be appended a". If you use general rule like "text = text.replace('a', 'e')", you will lose all your exceptions, because; when you replace all of your 'a's with 'e', in the next step you won't know that if the letter 'e' was 'a' or original 'e'. Thus, you won't able to use the rule "final e should be appended a". However, there is an easy solution for this problem. You can replace your exceptions with special latters such that '%' (like printf function in c language), so now you can use general rule and this time you won't lose all your exceptions. For example, lets replace all final 'e's with '%1%' and singular 'a's with '%%%'. Then we can replace all 'a's with 'e'. Now, the program didn't touch our exceptions. This time we will use other rules on our special characters. Let's replace our '%1%'s with 'e-a 's and '%%%'s with 'a'. We can use this technique to replace other words.

I showed you how to write Bork Bork! plugin with this easy and useful technique. I hope this will help you in your study. Have a nice day!

Comments

Comments powered by Disqus