Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix language #2740

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/robotide/editor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def obtain_language(existing, content):
doc_lang = read_language(content)
# print(f"DEBUG: textedit.py validate_and_update obtain_language={doc_lang}")
if doc_lang is not None:
mlang = Language.from_name(doc_lang.replace('_','-'))
try:
mlang = Language.from_name(doc_lang.replace('_','-'))
except ValueError as e:
raise e
set_lang[0] = get_rf_lang_code(mlang.code) # .code.replace('-','_')
elif len(set_lang) > 0:
if existing is not None:
Expand Down Expand Up @@ -375,8 +378,13 @@ def set_editor(self, editor):

def validate_and_update(self, data, text, lang='en'):
m_text = text.decode("utf-8")
initial_lang = self._doc_language or lang
if "Language: " in m_text:
self._doc_language = obtain_language(lang, text)
try:
self._doc_language = obtain_language(lang, text)
except ValueError:
# wx.MessageBox(f"Error when selecting Language: {e}", 'Error')
self._doc_language = 'en'
# print(f"DEBUG: textedit.py validate_and_update Language in doc--> lang={self._doc_language}")
else:
self._doc_language = lang if lang is not None else 'en'
Expand All @@ -390,6 +398,9 @@ def validate_and_update(self, data, text, lang='en'):
if not handled:
return False
# DEBUG: self._editor.reset()
# Language.name() # here get content in En to transform in Lang
# print(f"DEBUG: texteditor.py validate_and_update {initial_lang=} parameter lang={lang}"
# f" doc_language={self._doc_language} reformat_flag={self._editor.reformat}")
if self._editor.reformat:
data.update_from(data.format_text(m_text))
else:
Expand All @@ -412,15 +423,18 @@ def _sanity_check(self, data, text):
rf_lang = get_rf_lang_code(self._doc_language)
# print(f"DEBUG: textedit.py _sanity_check data is type={type(data)} lang={self._doc_language},"
# f" transformed lang={rf_lang}")
model = get_model(text, lang=rf_lang)
try:
model = get_model(text, lang=rf_lang)
except AttributeError:
return "Failed validation by Robot Framework", "Please, check if Language setting is valid!"
# print(f"DEBUG: textedit.py _sanity_check model is {model} doc language={self._doc_language}")
validator = ErrorReporter()
result = None
try:
validator.visit(model)
except DataError as err:
result = (err.message, err.details)
# model.save("/tmp/model_saved_from_RIDE.robot")
model.save("/tmp/model_saved_from_RIDE.robot")
# print(f"DEBUG: textedit.py _sanity_check after calling validator {validator}\n"
# f"Save model in /tmp/model_saved_from_RIDE.robot"
# f" result={result}")
Expand Down
12 changes: 6 additions & 6 deletions src/robotide/lib/robot/parsing/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def start_table(self, header_row, lineno: int, llang: list):
self.keyword_table = table = KeywordTable(self, self.language)
self.tables.append(self.keyword_table)
if table.type == 'variable':
self.variable_table = table = VariableTable(self)
self.variable_table = table = VariableTable(self, self.language)
self.tables.append(self.variable_table)
table.set_header(header_row, lineno=lineno)
# print(f"DEBUG: model _TestData start_table returning table={table} table name={table.name}\n"
Expand Down Expand Up @@ -323,7 +323,7 @@ def __init__(self, parent=None, source=None, settings=None, tasks=False, languag
self.tasks = tasks
self.language = language
self.setting_table = TestCaseFileSettingTable(self, self.tasks, self.language)
self.variable_table = VariableTable(self)
self.variable_table = VariableTable(self, self.language)
self.testcase_table = TestCaseTable(self, self.tasks, self.language)
self.keyword_table = KeywordTable(self, self.language)
self.comment_table = None # DEBUG: CommentsTable(self, self.language)
Expand Down Expand Up @@ -365,7 +365,7 @@ def __init__(self, source=None, settings=None, language=None):
if not self.language and source:
self.language = lang.check_file_language(source)
self.setting_table = ResourceFileSettingTable(self, self.language)
self.variable_table = VariableTable(self)
self.variable_table = VariableTable(self, self.language)
self.testcase_table = TestCaseTable(self, self.language)
self.keyword_table = KeywordTable(self, self.language)
self.comment_table = None # DEBUG: CommentsTable(self, self.language)
Expand Down Expand Up @@ -418,7 +418,7 @@ def __init__(self, parent=None, source=None, settings=None, tasks=False, languag
self.tasks = tasks
self.language = language
self.setting_table = InitFileSettingTable(self, self.tasks, self.language)
self.variable_table = VariableTable(self)
self.variable_table = VariableTable(self, self.language)
self.testcase_table = TestCaseTable(self, self.tasks, self.language)
self.keyword_table = KeywordTable(self, self.language)
self.comment_table = None # DEBUG: CommentsTable(self, self.language)
Expand Down Expand Up @@ -764,10 +764,10 @@ def __iter__(self):
class VariableTable(_Table):
type = 'variable'

def __init__(self, parent):
def __init__(self, parent, language=None):
_Table.__init__(self, parent)
self.variables = []
self.language = ''
self.language = language

@property
def _old_header_matcher(self):
Expand Down
5 changes: 4 additions & 1 deletion src/robotide/lib/robot/parsing/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ class FromFilePopulator(object):
_populators = {'setting': SettingTablePopulator,
'settings': SettingTablePopulator,
'variable': VariableTablePopulator,
'variables': VariableTablePopulator,
'test case': TestTablePopulator,
'test cases': TestTablePopulator,
'task': TestTablePopulator,
'tasks': TestTablePopulator,
'keyword': KeywordTablePopulator,
'keywords': KeywordTablePopulator,
'comments': CommentsTablePopulator}

def __init__(self, datafile, tab_size=2, lang=None):
Expand Down Expand Up @@ -124,7 +126,8 @@ def start_table(self, header, lineno: int, llang: list = None):
# # return False
self._populator.populate()
table = self._datafile.start_table(DataRow(header).all, lineno=lineno, llang=llang)
# print(f"DEBUG: populators start_table header={header} got table={table} at lineno={lineno}")
# print(f"DEBUG: populators start_table header={header} got table={table} at lineno={lineno}"
# f" llang={llang}")
if header[0] in language.get_headers_for(llang, ('Comment', 'Comments'), lowercase=False):
self._populator = self._populators['comments'](table)
else:
Expand Down
Loading
Loading