How do I translate user input into a fictitious language?

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.

2

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.

3

I did this for a chat program once. You dont need a toolkit. Just parse the text thats entered (ie, separate by spaces) and keep the words in an array. Then start working through them, looking at the words and any subsequent words. Match the sequences with your dialect/slang, and for any match, do the substitution. So as you work through the words, you’d build the output string either from the original word, or from any substitutions you found.

Might help to maintain two arrays – one that maintains the case and punctuation, and the other that converts text to lower case to make your checks against the dictionary simpler. Make sure their array indexes match. This way when you dont find a match in the array with lower case text, you can output the original, unmodified text.

For the dictionary, in PHP, you can take advantage of its arrays – perhaps build it like $words['find'] = 'replace'. Or for multi-word sequences, make it a nested array.

That should get you a decent first pass at a translator. You’ll probaby then have to consider how to handle things like “text in quotes” and other punctuation.

You are looking for something like this chef/jive/val/pig translator (there is c/lex source there).

The piglatin translator works through each word and reorders the characters.

The jive and val translators identify certain entire words and replaces them with alternate entire words (with some randomization tossed in at times).

http://www.ibm.com/developerworks/linux/library/l-perl-parsing/ works on translating a lex grammar into perl (and incidentally, works on the chef.l file from the first link). It links the perl source for a completed translation which may be of use for a php programmer.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật