|
|
@ -11,12 +11,13 @@ from rest_framework.response import Response
|
|
|
|
class ComponentI18nApi(RetrieveAPIView):
|
|
|
|
class ComponentI18nApi(RetrieveAPIView):
|
|
|
|
base_path = 'locale'
|
|
|
|
base_path = 'locale'
|
|
|
|
permission_classes = [AllowAny]
|
|
|
|
permission_classes = [AllowAny]
|
|
|
|
|
|
|
|
lang_data = {}
|
|
|
|
|
|
|
|
|
|
|
|
def retrieve(self, request, *args, **kwargs):
|
|
|
|
def get_component_translations(self, name):
|
|
|
|
name = kwargs.get('name')
|
|
|
|
if name in self.lang_data:
|
|
|
|
component_dir = safe_join(settings.APPS_DIR, 'i18n', name)
|
|
|
|
return self.lang_data[name]
|
|
|
|
lang = request.query_params.get('lang')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
component_dir = safe_join(settings.APPS_DIR, 'i18n', name)
|
|
|
|
if os.path.exists(component_dir):
|
|
|
|
if os.path.exists(component_dir):
|
|
|
|
files = os.listdir(component_dir)
|
|
|
|
files = os.listdir(component_dir)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -28,6 +29,13 @@ class ComponentI18nApi(RetrieveAPIView):
|
|
|
|
_lang = file.split('.')[0]
|
|
|
|
_lang = file.split('.')[0]
|
|
|
|
with open(safe_join(component_dir, file), 'r') as f:
|
|
|
|
with open(safe_join(component_dir, file), 'r') as f:
|
|
|
|
data[_lang] = json.load(f)
|
|
|
|
data[_lang] = json.load(f)
|
|
|
|
|
|
|
|
self.lang_data[name] = data
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def retrieve(self, request, *args, **kwargs):
|
|
|
|
|
|
|
|
name = kwargs.get('name')
|
|
|
|
|
|
|
|
lang = request.query_params.get('lang')
|
|
|
|
|
|
|
|
data = self.get_component_translations(name)
|
|
|
|
|
|
|
|
|
|
|
|
if lang:
|
|
|
|
if lang:
|
|
|
|
data = data.get(lang) or {}
|
|
|
|
data = data.get(lang) or {}
|
|
|
|