-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
214 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
from . import workspace | ||
from .logging import log | ||
from .place import Place | ||
|
||
|
||
routes = {} | ||
|
||
|
||
class Language: | ||
find_pattern = """(['"]{1})%s\\1\\s*=>""" | ||
FILENAME = 'lang/%(vendor)s%(file)s.php' | ||
LANG_FILENAME = '%(vendor)s%(lang)s/%(file)s.php' | ||
|
||
def __init__(self): | ||
self.base = None | ||
self.langs = [] | ||
|
||
for folder in workspace.get_folders(): | ||
dirs = workspace.get_folder_path(folder, 'resources/lang/*') | ||
if dirs: | ||
self.base = os.path.dirname(dirs[0]) | ||
self.langs = [] | ||
for dir in dirs: | ||
self.langs.append(os.path.basename(dir)) | ||
log('lang base', self.base) | ||
log('langs', self.langs) | ||
return | ||
|
||
def get_place(self, path): | ||
split = path.split(':') | ||
vendor = '' | ||
# it's package trans | ||
if (3 == len(split)): | ||
vendor = 'vendor/' + split[0] + '/' | ||
keys = split[-1].split('.') | ||
path = self.FILENAME % {'vendor': vendor, 'file': keys[0]} | ||
|
||
uris = [] | ||
paths = [] | ||
for lang in self.langs: | ||
lang_path = self.LANG_FILENAME % { | ||
'vendor': vendor, | ||
'lang': lang, | ||
'file': keys[0], | ||
} | ||
paths.append('lang/' + lang_path) | ||
|
||
uri = os.path.join(self.base, lang_path) | ||
if workspace.is_file(uri): | ||
uris.append(uri) | ||
|
||
location = None | ||
if (2 <= len(keys)): | ||
location = self.find_pattern % (keys[1]) | ||
|
||
place = Place(path, location) | ||
place.paths = paths | ||
place.paths.sort() | ||
place.uris = uris | ||
|
||
return place |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
class Place: | ||
import json | ||
|
||
|
||
class Place: | ||
def __init__(self, path, location=None, uri=None): | ||
self.path = path | ||
self.location = location | ||
self.is_controller = False | ||
self.paths = [] | ||
self.uri = uri | ||
self.paths = [] | ||
self.uris = [] | ||
|
||
def __str__(self): | ||
return json.dumps({ | ||
"path": self.path, | ||
"location": self.location, | ||
"is_controller": self.is_controller, | ||
"uri": self.uri, | ||
"paths": self.paths, | ||
"uris": self.uris | ||
}, sort_keys=True, indent=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Title', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Titre', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from . import unittest | ||
from unittest.mock import patch | ||
from LaravelGoto.lib.language import Language | ||
|
||
|
||
class TestLanguage(unittest.ViewTestCase): | ||
@patch('LaravelGoto.lib.workspace.get_folders') | ||
def test_get_place(self, mock_get_folders): | ||
mock_get_folders.return_value = [self.get_test_dir()] | ||
|
||
language = Language() | ||
place = language.get_place('blog.title') | ||
|
||
self.assertEqual(place.path, 'lang/blog.php') | ||
self.assertEqual( | ||
place.paths, [ | ||
'lang/en/blog.php', | ||
'lang/fr/blog.php', | ||
]) | ||
self.assertEqual(len(place.uris), 2) | ||
|
||
## vendor | ||
place = language.get_place('pkg::blog.title') | ||
|
||
self.assertEqual(place.path, 'lang/vendor/pkg/blog.php') | ||
self.assertEqual( | ||
place.paths, [ | ||
'lang/vendor/pkg/en/blog.php', | ||
'lang/vendor/pkg/fr/blog.php', | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters