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 CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by