Skip to content

Commit

Permalink
Manually create localized paragraphs
Browse files Browse the repository at this point in the history
This allows us to have localized content instead of Lorem Ipsum text

Fixes #12
  • Loading branch information
nitriques committed Jan 10, 2017
1 parent 5104e5b commit ea37e5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions lib/adapters/class.multilingualfieldadapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public function data($section, $field)
{
$multingual_values = array();
foreach (FLang::getLangs() as $lc) {
// fix length since we add chars...
$length = General::intval($field->get('text_length')) - strlen($lc) - 1;
$length = General::intval($field->get('text_length'));
$value = $this->generateValue($field, $length, $lc);
$multingual_values[$lc] = strtoupper($lc) . ' ' . $value;
$multingual_values[$lc] = $value;
}
return $this->processRawFieldData($field, $multingual_values);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/generators/class.textgenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ class TextGenerator
);
public static function generate($options)
{
$options = array_merge($options, self::$defaultOptions, $options);
$options = array_merge(self::$defaultOptions, $options);
$plimit = max(1, General::intval($options['paragraphs']));
$faker = FieldAdapter::faker($options['locale']);
$value = $faker->paragraphs($plimit);
$value = implode(PHP_EOL . PHP_EOL, $value);
$maxLength = General::intval($options['max-length']);
$maxLength = $maxLength < 1 ? 1024 : $maxLength;
$faker = FieldAdapter::faker($options['locale']);
$paragraphs = array();
for ($p = 0; $p < $plimit; $p++) {
$paragraphs[] = $faker->realText(max(10, $maxLength / $plimit));
}
$value = implode(PHP_EOL . PHP_EOL, $paragraphs);
if ($maxLength > 0 && General::strlen($value) > $maxLength) {
$value = General::substr($value, 0, $maxLength);
}
Expand Down

0 comments on commit ea37e5c

Please sign in to comment.