Skip to content

Text domain header#43

Merged
schlessera merged 3 commits intomasterfrom
text-domain-header
Jul 10, 2018
Merged

Text domain header#43
schlessera merged 3 commits intomasterfrom
text-domain-header

Conversation

@swissspidy
Copy link
Copy Markdown
Member

Fixes #41.

Note: while working on this I uncovered a bug in the destination file determination.

It previously used isset() to check whether the Domain Path header was present. However, it is always set, but can be empty.

This meant that the default value, $this->destination = $this->slug . '.pot'; was never used. Also, that default value is wrong anyway as it doesn't generate the POT file in the plugin's directory, but the current working dir.

}

// Determine destination.
$this->destination = $this->source . DIRECTORY_SEPARATOR . $this->slug . '.pot';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of DIRECTORY_SEPARATOR is actually not a good practice here. That constant should be sued for functions like explode() or (r|l)trim. If you compose a filesystem string for the server, just use / instead.

So, I'd write this line as follows:

$this->destination = "{$this->source}/{$this->slug}.pot";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense!


if ( ! empty( $file_data['Domain Path'] ) ) {
// Domain Path inside source folder.
$this->destination = $this->source . DIRECTORY_SEPARATOR . $file_data['Domain Path'] . DIRECTORY_SEPARATOR . $this->slug . '.pot';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, use of DIRECTORY_SEPARATOR counterproductive here.

* @return string String without leading and trailing slashes.
*/
protected function unslashit( $string ) {
return ltrim( rtrim( $string, '/\\' ), '/\\' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would actually be a good use of DIRECTORY_SEPARATOR. However, as we are not quite sure what we get and what we already did with it, I'd say we leave it as is now to stay on the safe side (especially with Cygwin on Windows).

@schlessera schlessera added this to the 0.1.0 milestone Jul 10, 2018
@schlessera schlessera added the command:i18n-make-pot Related to 'i18n make-pot' command label Jul 10, 2018
@schlessera schlessera merged commit bd16b5f into master Jul 10, 2018
@schlessera schlessera deleted the text-domain-header branch July 10, 2018 15:02
@schlessera schlessera added the bug label Jul 10, 2018
schlessera added a commit that referenced this pull request Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:i18n-make-pot Related to 'i18n make-pot' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants