开发者

Need some input on how to build a large scale text replacement system

My Rails app deals a lot with data from third-party APIs (specifically UPS, FedEx, DHL, etc).

What I'd like to do is whenever that data comes in, replace certain phrases with customized phrases.

Example: "On FedEx vehicle for delivery" (which we get from the FedEx API), I'd like to replace with "Out for Delivery."

Is it best to replace the the text on its way in 开发者_运维问答to the database? Or on output? (Talking from an end-user speed perspective)

I'm planning on storing these phrases in our database, so I'm assuming I'd just create a helper that pulls the phrases I want to replace and then run the strings through those using gsub and replace as necessary?

Any tips on making this efficient and easy to manage would be great.


For speed you should replace the phrases when they enter the database. If you do it on output you'll have to do it every time an user requests the data. It is quite obvious that doing it every time will put more load on the server.

You may, however, want to store the original phrases, in case you want to change the wording in the phrases you replace with.


Just a random idea, which might not be applicable depending on how your data is, but maybe you could leverage the i18n framework that's built into Rails for this. The original text could be viewed as a separate language called vendorspeak :-).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜