Skip to content

Commit 83d15eb

Browse files
committed
Add lang_path
1 parent 10ccfe5 commit 83d15eb

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/class-elda.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Elda {
3232
'files' => [],
3333
'instance' => '',
3434
'lang_dir' => 'languages',
35+
'lang_path' => '',
3536
'namespace' => '',
3637
'src_dir' => 'src'
3738
];
@@ -166,7 +167,12 @@ protected function load_textdomain() {
166167
return;
167168
}
168169

169-
$path = $this->get_path( $this->options->lang_dir );
170+
$path = $this->options->lang_path;
171+
172+
if ( empty( $path ) ) {
173+
$path = $this->get_path( $this->options->lang_dir );
174+
}
175+
170176
$path = sprintf( '%s/%s-%s.mo', rtrim( $path, '/' ), $domain, get_locale() );
171177

172178
load_textdomain( $domain, $path );
@@ -261,6 +267,10 @@ protected function set_options( array $options ) {
261267
throw new InvalidArgumentException( 'Invalid argument. `lang_dir` must be string.' );
262268
}
263269

270+
if ( ! is_string( $this->options->lang_path ) ) {
271+
throw new InvalidArgumentException( 'Invalid argument. `lang_path` must be string.' );
272+
}
273+
264274
if ( ! is_string( $this->options->namespace ) ) {
265275
throw new InvalidArgumentException( 'Invalid argument. `namespace` must be string.' );
266276
}

tests/class-elda-test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ public function test_options_exceptions() {
163163
$this->assertEquals( 'Invalid argument. `lang_dir` must be string.', $e->getMessage() );
164164
}
165165

166+
try {
167+
Elda::boot( __DIR__, [
168+
'lang_path' => false
169+
] );
170+
} catch ( \InvalidArgumentException $e ) {
171+
$this->assertEquals( 'Invalid argument. `lang_path` must be string.', $e->getMessage() );
172+
}
173+
166174
try {
167175
Elda::boot( __DIR__, [
168176
'namespace' => false

0 commit comments

Comments
 (0)