如何正确地国际化 Sinatra 页面?
How to properly internationalize a Sinatra page?
我有一个 Sinatra route file, which displays some page。
<h2>Free, open song contest</h2>
<h3>Sign up</h3>
<form action="/signup" method="post">
E-mail: <input type="text" name="email" placeholder="Your e-mail"><br/>
Password: <input type="password" name="password"><br/>
Repeat password: <input type="password" name="password2"><br/>
Account type: <input type="radio" checked="true" name="type" value="fan">Fan
<input type="radio" name="type" value="musician">Musician
</form>
<h3>Log in</h3>
<form action="/login" method="post">
E-mail: <input type="text" name="email" placeholder="Your e-mail"><br/>
Password: <input type="password" name="password"><br/>
</form>
如果我想国际化此页面中的所有字符串(免费,打开歌曲比赛,注册,电子邮件等),正确的做法是什么?
我在上面的例子中找到了这个i18n recipe, but it doesn't tell, how to insert the internationalized strings into the template (home.erb。
在同一个 documentation 页面中,后面写着:
Selection of localized strings/objects is easy as it only requires use
of standard methods from I18n
I18n.t(:token)
I18n.l(Time.now)
所以,你需要做:
<h2>I18n.t(:contest_page_title')</h2>
并且,在您的 locales/en.yml
中,您将拥有:
en:
contest_page_title: Free, open song contest
由于i18n
gem也用于Rails,国际化的基本方面也可以从Rails guide
中推断出来
我有一个 Sinatra route file, which displays some page。
<h2>Free, open song contest</h2>
<h3>Sign up</h3>
<form action="/signup" method="post">
E-mail: <input type="text" name="email" placeholder="Your e-mail"><br/>
Password: <input type="password" name="password"><br/>
Repeat password: <input type="password" name="password2"><br/>
Account type: <input type="radio" checked="true" name="type" value="fan">Fan
<input type="radio" name="type" value="musician">Musician
</form>
<h3>Log in</h3>
<form action="/login" method="post">
E-mail: <input type="text" name="email" placeholder="Your e-mail"><br/>
Password: <input type="password" name="password"><br/>
</form>
如果我想国际化此页面中的所有字符串(免费,打开歌曲比赛,注册,电子邮件等),正确的做法是什么?
我在上面的例子中找到了这个i18n recipe, but it doesn't tell, how to insert the internationalized strings into the template (home.erb。
在同一个 documentation 页面中,后面写着:
Selection of localized strings/objects is easy as it only requires use of standard methods from I18n
I18n.t(:token) I18n.l(Time.now)
所以,你需要做:
<h2>I18n.t(:contest_page_title')</h2>
并且,在您的 locales/en.yml
中,您将拥有:
en:
contest_page_title: Free, open song contest
由于i18n
gem也用于Rails,国际化的基本方面也可以从Rails guide