Php – How to translate user input into a fictitious language

parsingPHPtranslate

For experimental reasons, I am trying to convert user input into a fictitious language. All of the translation can be 1:1.

I would prefer if I could accomplish this with PHP.

Should I use gettext and poedit? The fictitious language is not very large, I imagine I can do most of the translation 1:1

I have scoured the googles, but have only found dated code and localization.

Best Answer

gettext is the wrong tool for that job. It is intended to translate a potentially large but finite well-defined set of pre-formulated messages, possibly with variable insertions, between languages. User input in natural language is not such a set. You are better off defining the transformations you need to make in general terms and apply them to the input you get, e.g. as a set of regex transformations stored in a map of from-to pairs. That is easily done in PHP.

But note that there will almost certainly be things that you cannot achieve with such simple replacements. "you all" may usually be transform to "y'all", but what about "Let me show you all our biggest sellers"? Depending on how convincing you need the result to be, the task may be stupendously more difficult than it appears at first sight. Natural language translation, even if it's only a "dialect", is a T. Rex in sheep's clothing.

Related Topic