[英]What is the most effective way to translate string names from database in Laravel
I am currently building a small social network with language select. 我目前正在建立一个带有语言选择功能的小型社交网络。 My problem is what I'm clueless with is i have user groups saved in the database.
我的问题是我一无所知,因为我将用户组保存在数据库中。
id name
1 Model
2 Photographer
3 Makeup artist
I select these and place it in to my signup form 我选择这些并将其放入我的注册表单
<div class="form-group">
{{ Form::label('group', Lang::get('auth.group'), array("class" => "col-lg-3 control-label ")) }}
<div class="col-lg-8">
<select class="col-lg-12" name="group_id[]" id="" multiple size="6" >
@foreach($groups as $group)
<option value="{{ $group->id }}">{{ $group->name }}</option>
@endforeach
</select>
</div>
</div>
But I'm totally clueless how to translate these, I am using Laravel's Localization
. 但是我完全不知道如何翻译这些内容,我正在使用
Laravel's Localization
。
Could someone please give me a hint about this? 有人可以给我一个提示吗?
If you want to localize string that come from your database, then you have to store the keys into your database tables. 如果要本地化来自数据库的字符串,则必须将键存储到数据库表中。 Then in your views you translate as you will normally do in Laravel.
然后在您的视图中进行翻译,就像通常在Laravel中一样。
A database table will have a the following structure (note that apart from the name you will also store a key): 数据库表将具有以下结构(请注意,除了名称之外,您还将存储键):
-------------------------------------------
| ID | Name | NameKey |
===========================================
| 1 | Model | group.model |
| 2 | Photographer | group.photographer |
| 3 | Makeup Artist | group.makeupartist |
-------------------------------------------
The name will not me mandatory, but it is useful when the key are not clearly understandable. 该名称不是强制性的,但是在无法清晰理解键的情况下很有用。
Then your view, instead of rendering the name you will render the key localized: 然后,您的视图将呈现本地化的键,而不是呈现名称 :
<option value="{{ $group->id }}">{{ Lang::get($group->nameKey) }}
Another suggestions would be using the name itself as the key, but it could problematic when two words that are the same has different meaning in a language, but in another language it is written differently. 另一个建议是使用名称本身作为关键字,但是如果两个相同的单词在一种语言中具有不同的含义,而在另一种语言中其书写方式不同,则可能会出现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.