How to change generated text language in fzaninotto / faker?

In Laravel, I use Faker. ( fzaninotto / faker )

It is not possible to change the language (language) of the generated texts.

My code is:

use Faker\Factory as Faker; class MySeeder extends Seeder { public function run() { $faker = Faker::create('ru_RU'); $randomSentence = $faker->sentence(); ... } } 

But as a result, $randomSentence contains the generated text from the default locale ('en_EN').

PS Updated by Faker. The folder '\ vendor \ fzaninotto \ faker \ src \ Faker \ Provider \ ru_RU' contains Text.php

+5
source share
1 answer

The reason you do not get Russian text from the sentence() method is because it does not use text from Text.php .

The sentence() method is defined in Lorem.php and uses the list of words in this file. You either need to use the realText() method, or implement the Russian version of the dictionary list (which the author of Faker has already said no )

In short, you need to use this line to get the Russian text:

 $faker = Faker::create('ru_RU'); $randomSentence = $faker->realText(); 
+6
source

Source: https://habr.com/ru/post/1209985/


All Articles