Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change generated text's language in fzaninotto/Faker?

In Laravel I use Faker. (fzaninotto/Faker)

Can't change locale(language) of generated texts.

My code:

use Faker\Factory as Faker;

class MySeeder extends Seeder {    

    public function run() {
        $faker = Faker::create('ru_RU');

        $randomSentence = $faker->sentence();
        ...
    }
}

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

P.S. Faker is updated. Folder '\vendor\fzaninotto\faker\src\Faker\Provider\ru_RU' contains Text.php

like image 556
YanDatsiuk Avatar asked Dec 28 '14 11:12

YanDatsiuk


1 Answers

The reason you're not getting Russian text from the sentence() method is that it's not using the text from Text.php.

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

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

$faker = Faker::create('ru_RU');
$randomSentence = $faker->realText();
like image 112
Ulrik Avatar answered Oct 15 '22 07:10

Ulrik