Laravel具有动态语言环境的可翻译工厂种子

时间:2018-07-01 07:57:08

标签: laravel-5 laravel-seeding laravel-translatable

我想在不对语言环境进行硬编码的情况下为可翻译模型提供工厂种子。

我必须输入两个值,即不可翻译的slug和 标题,必须将其翻译成语言表中的所有语言。

这是出厂文件:

\bthird number

这给了我一个错误:

  

未找到列:1054未知列“ hr”

工厂创建的查询:

  

插入   到 SrcObj src = new SrcObj("src name", 1); DestObj dest = new DestObj(null, 0, 1, true); ModelMapper modelMapper = ObjectMapper.modelMapper(); modelMapper.map(src, dest); System.out.println(dest); $factory->define(App\Category::class, function (Faker $faker) { $counter = 1; $locales = Language::pluck('lang'); //returns hr,en,de $titles = []; foreach ($locales as $locale) { $titles[$locale] = [ 'title' => 'Title for category-' .$counter++. ' on '. $locale . ' language' ]; } /* $titles = "hr" => array:1 [ "title" => "Title for category-1 on hr language" ] "en" => array:1 [ "title" => "Title for category-2 on en language" ... */ return [ 'slug' => 'category-'.$counter++, $titles ]; }); category_translationslocalehrende)值(0,类别标题hr语言-1,标题    关于英语的第二类,关于德兰瓜的第三类的标题   e,测试语言的4类标题,20))

1 个答案:

答案 0 :(得分:0)

经过一些实验,我找到了一个解决方案,这里是:

alert.setValue(NSAttributedString(string: alert.message, attributes: [NSAttributedStringKey : UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.Medium), NSAttributedStringKey.foregroundColor : UIColor.green]), forKey: "attributedMessage")