Skip to content

Commit

Permalink
Merge pull request #20 from 26B/fix/path-without-locale
Browse files Browse the repository at this point in the history
  • Loading branch information
goncaloasimoes authored Jan 14, 2021
2 parents a785725 + 3f21ef1 commit 0f3beaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/Config/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,25 @@ public function get_path( string $locale ) : string {
return $path . "{$locale}.{$this->config['ext']}";
}

$filename_parts = [];

if ( isset( $this->config['filename'] ) ) {
$path .= "{$this->config['filename']}-";
$filename_parts[] = "{$this->config['filename']}";

} elseif ( isset( $this->config['domain'] ) ) {
$path .= "{$this->config['domain']}-";
$filename_parts[] = "{$this->config['domain']}";
}

if ( ! empty( $locale ) ) {
$path .= "{$locale}";
$filename_parts[] = "{$locale}";
}

// TODO: Should we only add this if the format/ext is also jed/json?
if ( isset( $this->config['js-handle'] ) ) {
$path .= "-{$this->config['js-handle']}";
$filename_parts[] = "{$this->config['js-handle']}";
}

$path .= implode( '-', $filename_parts );
return "{$path}.{$this->config['ext']}";
}

Expand Down
11 changes: 10 additions & 1 deletion tests/Config/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,16 @@ public function getPathData() : array {
],
'pt_PT',
"{$path}pt_PT.{$ext}",
]
],
'Empty locale' => [
[
'path' => $path,
'ext' => $ext,
'domain' => $domain,
],
'',
"{$path}{$domain}.{$ext}",
],
];
}

Expand Down

0 comments on commit 0f3beaf

Please sign in to comment.