Skip to content

Commit

Permalink
Language choice
Browse files Browse the repository at this point in the history
  • Loading branch information
technosf committed Jan 8, 2025
1 parent cdb95bd commit 1a50795
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 25 deletions.
5 changes: 5 additions & 0 deletions data/com.github.louis77.tuner.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@
<summary>Theme mode</summary>
<description>Which theme the app should use</description>
</key>
<key name="language" type="s">
<default>""</default>
<summary>Display Language</summary>
<description>Language to use for UI</description>
</key>
</schema>
</schemalist>
58 changes: 46 additions & 12 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ namespace Tuner {

private static Gtk.Settings GTK_SETTINGS;
private static string GTK_SYSTEM_THEME = "unset";
private static string ENV_LANG = "LANGUAGE";

/** @brief Application version */
public const string APP_VERSION = VERSION;
Expand All @@ -185,19 +186,57 @@ namespace Tuner {

/** @brief Unicode character for out-of-date items */
public const string EXCLAIM_CHAR = "";

/** @brief File name for starred station sore */
public const string STARRED = "starred.json";

public static Gee.Collection<string> LANGUAGES = new Gee.TreeSet<string>();

/** @brief Connectivity monitoring*/
private static NetworkMonitor NETMON = NetworkMonitor.get_default ();

private static Gtk.CssProvider CSSPROVIDER = new Gtk.CssProvider();

public static string SYSTEM_THEME() { return GTK_SYSTEM_THEME; }

static construct
{
// Interntionalization
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);
LANGUAGES.add("en"); // App core language
try {
// Add translations
var dir = File.new_for_path(LOCALEDIR);
var enumerator = dir.enumerate_children("standard::*", FileQueryInfoFlags.NONE);
FileInfo info;
while ((info = enumerator.next_file()) != null)
{
if (info.get_file_type() == FileType.DIRECTORY && info.get_name() != "C")
{
var lang_dir = dir.get_child(info.get_name());
var mo_file = lang_dir.get_child("LC_MESSAGES").get_child(GETTEXT_PACKAGE + ".mo");
if (mo_file.query_exists()) LANGUAGES.add(info.get_name());
}
} // while
} catch (Error e) {
warning(@"Error reading locale path: $(e.message)");
}
}

// -------------------------------------

public string language {
get { return GLib.Environment.get_variable(ENV_LANG); }
set {
if ( GLib.Environment.get_variable(ENV_LANG) == value
|| ( value != "" && !LANGUAGES.contains(value )) ) return;
GLib.Environment.set_variable(ENV_LANG, value, true);
settings.language = value;
}
}

/** @brief Application settings */
public Settings settings { get; construct; }
Expand All @@ -222,7 +261,6 @@ namespace Tuner {

public Cancellable offline_cancel { get; construct; }

public static string SYSTEM_THEME() { return GTK_SYSTEM_THEME; }


/** @brief Are we online */
Expand Down Expand Up @@ -273,12 +311,7 @@ namespace Tuner {
* @brief Construct block for initializing the application
*/
construct
{
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);

{
// Create required directories and files

cache_dir = stat_dir(Environment.get_user_cache_dir ());
Expand Down Expand Up @@ -381,21 +414,22 @@ namespace Tuner {
protected override void activate()
{
if (window == null) {
window = new Window (this, player, settings, directory);
DBus.initialize ();
settings.configure();

GTK_SETTINGS = Gtk.Settings.get_default();
GTK_SYSTEM_THEME = GTK_SETTINGS.gtk_theme_name;
apply_theme_name( settings.theme_mode);

CSSPROVIDER.load_from_resource ("/com/github/louis77/tuner/css/Tuner-system.css");
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
CSSPROVIDER,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);

apply_theme_name( settings.theme_mode);
language = settings.language;

window = new Window (this, player, settings, directory);
settings.configure();
add_window (window);
} else {
window.present ();
Expand Down
7 changes: 5 additions & 2 deletions src/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Tuner.Settings : GLib.Settings
private const string SETTINGS_STREAM_INFO = "stream-info";
private const string SETTINGS_STREAM_INFO_FAST = "stream-info-fast";
private const string SETTINGS_THEME_MODE = "theme-mode";
private const string SETTINGS_LANGUAGE = "language";
private const string SETTINGS_VOLUME = "volume";
private const string SETTINGS_WINDOW_HEIGHT = "window-height";
private const string SETTINGS_WINDOW_WIDTH = "window-width";
Expand All @@ -29,6 +30,7 @@ public class Tuner.Settings : GLib.Settings
public bool stream_info { get; set; }
public bool stream_info_fast { get; set; }
public string theme_mode { get; set; }
public string language { get; set; }
public double volume { get; set; }

private int _pos_x;
Expand All @@ -54,6 +56,7 @@ public class Tuner.Settings : GLib.Settings
stream_info = get_boolean(SETTINGS_STREAM_INFO);
stream_info_fast = get_boolean(SETTINGS_STREAM_INFO_FAST);
theme_mode = get_string(SETTINGS_THEME_MODE);
language = get_string(SETTINGS_LANGUAGE);
volume = get_double(SETTINGS_VOLUME);
} // Settings

Expand All @@ -62,8 +65,7 @@ public class Tuner.Settings : GLib.Settings
{
app().window.resize(_window_width, _window_height);
app().window.move(_pos_x, _pos_y);
app().player.volume = _volume;

app().player.volume = _volume;
} // configure


Expand All @@ -86,6 +88,7 @@ public class Tuner.Settings : GLib.Settings
set_boolean(SETTINGS_STREAM_INFO, stream_info);
set_boolean(SETTINGS_STREAM_INFO_FAST, stream_info_fast);
set_string(SETTINGS_THEME_MODE, theme_mode);
set_string(SETTINGS_LANGUAGE, language);
set_double(SETTINGS_VOLUME, app().player.volume);
} // save
} // Tuner.Settings
15 changes: 7 additions & 8 deletions src/Widgets/Display.vala
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public class Tuner.Display : Gtk.Paned, StationListHookup {
if (_first_activation)
// One time set up - do post initialization
{
// TBD
_first_activation = false;
initialize.begin(() =>
{
Expand Down Expand Up @@ -323,11 +322,11 @@ public class Tuner.Display : Gtk.Paned, StationListHookup {
, _selections_category
, "discover"
, "face-smile"
, "Discover"
, "Stations to Discover"
, _("Discover")
, _("Stations to Discover")
, false
,_directory.load_random_stations(20)
, "Discover more stations"
, _("Discover more stations")
, "media-playlist-shuffle-symbolic");

discover.action_button_activated_sig.connect (() => {
Expand All @@ -344,8 +343,8 @@ public class Tuner.Display : Gtk.Paned, StationListHookup {
_selections_category,
"trending",
"playlist-queue",
"Trending",
"Trending Stations in the last 24 hours",
_("Trending"),
_("Trending Stations in the last 24 hours"),
_directory.load_trending_stations(40)
);

Expand All @@ -359,8 +358,8 @@ public class Tuner.Display : Gtk.Paned, StationListHookup {
, _selections_category
, "popular"
, "playlist-similar"
, "Popular"
, "Most listened to Stations in the last 24 hours"
, _("Popular")
, _("Most listened to Stations in the last 24 hours")
,_directory.load_popular_stations(40)
);

Expand Down
1 change: 0 additions & 1 deletion src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public class Tuner.HeaderBar : Gtk.HeaderBar
// Preferences button
_prefs_button.image = new Image.from_icon_name ("open-menu", IconSize.LARGE_TOOLBAR);
_prefs_button.valign = Align.CENTER;
// _prefs_button.sensitive = true;
_prefs_button.tooltip_text = _("Preferences");
_prefs_button.popover = new Tuner.PreferencesPopover();

Expand Down
28 changes: 26 additions & 2 deletions src/Widgets/PreferencesPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,32 @@ public class Tuner.PreferencesPopover : Gtk.Popover
stream_info.action_name = Window.ACTION_PREFIX + Window.ACTION_STREAM_INFO;
stream_info.tooltip_text = _("Cycle through the metadata from the playing stream");


var stream_info_fast = new Gtk.ModelButton ();
stream_info_fast.text = _("Faster cycling through stream info");
stream_info_fast.action_name = Window.ACTION_PREFIX + Window.ACTION_STREAM_INFO_FAST;
stream_info_fast.tooltip_text = _("Fast cycle through the metadata from the playing stream if show stream info is enabled");


//Language
var lang_combo = new Gtk.ComboBoxText ();
lang_combo.append("", _("Default"));
foreach( var lang in Application.LANGUAGES)
{
lang_combo.append(lang, lang);
}
lang_combo.halign = Gtk.Align.CENTER;
lang_combo.active_id = app().settings.language; // Initial state from settings

var lang_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 3);
lang_box.pack_end (lang_combo, true, true, 5);
lang_box.pack_end (new Gtk.Label(_("Language")), false, false, 12);
lang_box.tooltip_text = _("Requires restarting Tuner");

lang_combo.changed.connect ((elem) => {
app().language = elem.active_id;
});


// Export starred
var export_starred = new Gtk.ModelButton ();
export_starred.text = _("Export Starred Sations to Playlist");
Expand Down Expand Up @@ -123,7 +142,12 @@ public class Tuner.PreferencesPopover : Gtk.Popover

menu_grid.attach (new Gtk.SeparatorMenuItem (), 0, vpos++, 4, 1);

menu_grid.attach (lang_box, 0, vpos++, 4, 1);

menu_grid.attach (new Gtk.SeparatorMenuItem (), 0, vpos++, 4, 1);

menu_grid.attach (about_menuitem, 0, vpos++, 4, 1);

menu_grid.show_all ();

this.add (menu_grid);
Expand Down Expand Up @@ -183,7 +207,7 @@ public class Tuner.PreferencesPopover : Gtk.Popover
public void import_stationuuids()
{
var dialog = new Gtk.FileChooserDialog(
"Choose a file",
_("Choose a file"),
app().window,
Gtk.FileChooserAction.OPEN,
"_Cancel", Gtk.ResponseType.CANCEL,
Expand Down

0 comments on commit 1a50795

Please sign in to comment.