A little code to allow word substitution depending on user

I’m creating a demo web app in html in order for people to physically see and comment on the app prior to committing to a proper build.

Whilst the proper app will be database driven, my demo is just standard html with some JavaScript effects.

What I do want to demonstrate is that different user group will see different words. For example, imagine I have an html sentence that says:

This will cost £100 to begin.

What I need to some way of identifying that if the user has deemed themselves to be from the US, the sentence says:

This will cost $100 to begin.

This requirement is peppered throughout the pages but I’m happy to add each one manually. So I envisage some code along the lines of ‘first, remove the [boot US] trunk’ where the UK version is ‘first remove the boot’ but the code is saying that the visitor needs the US version. It then looks up boot (in an Access database perhaps) and sees that the table says for boot for US, display ‘trunk’.

I’m not a programmer but I can normally cobble together scripts so I’m hoping someone may have a relatively easy solution in JavaScript, CSS or ASP.

To recap: I have a number of words or short sentences that need to appear differently and I’m happy to manually insert each one if necessary (but would be even better if the words were automatically changed).
And I need a device which allows me to tell the pages to choose the US version, or for example, the New Zealand version.

1

The simplest approach to to this is to use localised “dictionaries”. This could be a table in the database or a “resource” file of strings, but the same principle applies.

You have a main dictionary that holds all of your text. This will be in the “neutral” language – the one where most of your users come from (for example).

You then have sub dictionaries for each language variant that holds the localised text. So your main dictionary (UK) will contain:

Id    Text
 1    First remove the boot

Your sub dictionary (US) will contain:

Id    Text
 1    First remove the trunk

Note that the ids are the same and that the whole phrase is present.

Then your application will check the users language (either by asking the user or by checking the locale of the browser/operating system they are using) and use the appropriate dictionary to find the text.

If the required id doesn’t exist in the sub dictionary it will then look in the main dictionary for the default text to use.

The whole test is present as translations aren’t usually as simple as replacing the odd word here and there. Often the same word (boot – footwear or part of car) has two or more meanings and a blind substitution doesn’t take context into account. Also, while you might start off with a UK/US system it might require other languages later. This scheme is also easier to implement than a word substitution one.

As for currency symbols – store the numeric value only and format it with the users culture to output it as a string. Most frameworks have this ability.

2

If all you want is a quick and dirty demo to show what functionality will be in the app without actually making a full blown app. Make every section of localized text its own container and have one container for each localization. Then just use JavaScript and CSS to hide/display the containers that match the desired location, your HTML page would look like this.

<p class='UK' >This will cost £100 to begin.</p>
<p class='US' >This will cost $100 to begin.</p>
<p class='CAN' >This will cost $150 to begin.</p>

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