GUI - switching language

1 回表示 (過去 30 日間)
keenN
keenN 2011 年 2 月 22 日
回答済み: Roberto 2014 年 4 月 26 日
Hello, I am working on a GUI with a language selection. I put the language selection in a listbox as strings. My question is, how do I program the GUI to be able to change all the texts in current GUI and all other connected GUIs according to the language selected? I'd really appreciate anyone's help. Thanks!

回答 (1 件)

Roberto
Roberto 2014 年 4 月 26 日
you'll have to store all the 'strings' in a external file, or in the same file but it's going to be huge: here's an idea of how to do it, as simple as 1,2,3:
1. Create a GUI with default text values and tag properties considering previous tags:
f= figure ;
h1 = uicontrol(f,'style','pushbutton','position',[10 10 200 20],...
'tag','txtOne','String','default text') ;
h2 = uicontrol(f,'style','text','position',[10 35 200 20],...
'tag','txtother','String','default text2') ;
2. Create a function to change the 'String' property for all elements
function changeLan(figureHandle,lanIndex)
tags = {'txtOne','txtother'} ;
strs{1} = {'My text', 'Other text'} ;
strs{2} = {'Mi texto', 'otro texto'} ;
for i = 1:length(tags)
handle = findobj(f,'tag',tags{i}) ;
set(handle,'String',strs{lanIndex}{i});
end
end
3. call the function to change the language:
changeLan(f,1);
changeLan(f,2);
Hope it will help you! :)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by