Skip to content

Conversation

@amieiro
Copy link
Member

@amieiro amieiro commented May 4, 2022

It is very usual that some strings to translate have empty spaces at their beginning or at the end.
The translators don't see if their translations have these empty spaces.

This PR adds some checks to warn the translators about these missing or unexpected spaces in their translations.

image

image

image

amieiro and others added 3 commits May 9, 2022 15:11
Remove unnecesary parenthesis.

Co-authored-by: Dominik Schilling <[email protected]>
Remove space.

Co-authored-by: Dominik Schilling <[email protected]>
@amieiro amieiro requested a review from ocean90 May 9, 2022 15:32
@amieiro
Copy link
Member Author

amieiro commented Jun 6, 2022

The execution time with regex takes half of the time vs mb_strlen. I have tested it with this code:

<?php // execution-time.php file

$original = ' Lorem ipsum ';
$translation = ' Lorem ipsum dolor sit ';
$number_of_executions = 10000000;

$time_start = microtime(true);

for ($i=0; $i<$number_of_executions; $i++){
	preg_match( '/^( *)/D', $original, $m );
	$original_start_spaces = strlen( $m[0] );

	preg_match( '/^( *)/D', $translation, $m );
	$translation_start_spaces = strlen( $m[0] );

	preg_match( '/( *)$/D', $original, $m );
	$original_end_spaces = strlen( $m[0] );

	preg_match( '/( *)$/D', $translation, $m );
	$translation_end_spaces = strlen( $m[0] );
}

$time_end = microtime(true);

echo 'Total execution time with regex: '.($time_end - $time_start).' s' . PHP_EOL;

for ($i=0; $i<$number_of_executions; $i++){
	$original_start_spaces    = mb_strlen( $original ) - mb_strlen( ltrim( $original, ' ' ) );
	$original_end_spaces      = mb_strlen( $original ) - mb_strlen( rtrim( $original, ' ' ) );
	$translation_start_spaces = mb_strlen( $translation ) - mb_strlen( ltrim( $translation, ' ' ) );
	$translation_end_spaces   = mb_strlen( $translation ) - mb_strlen( rtrim( $translation, ' ' ) );
}

$time_end = microtime(true);

echo 'Total execution time with mb_strlen: '.($time_end - $time_start).' s'. PHP_EOL;

Executing this code:

$ php execution-time.php
Total execution time with regex: 3.5283000469208 s
Total execution time with mb_strlen: 7.8940501213074 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants