Skip to content

Commit

Permalink
Translate pattern descriptions
Browse files Browse the repository at this point in the history
After changing the language refresh the repositories
and reload the data to get the pattern descriptions
in the new language.

The selected packages need to be restored after the
reload, the current selection is lost.
  • Loading branch information
lslezak committed Jan 11, 2024
1 parent a805fc2 commit 40bc3ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
44 changes: 35 additions & 9 deletions service/lib/agama/dbus/software_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,8 @@ def start
# registering the language change callback to work properly
export
@ui_locale = UILocale.new(Clients::Locale.instance) do |locale|
# set the locale in the Language module, when changing the repository
# (product) it calls Pkg.SetTextLocale(Language.language) internally
Yast::Language.Set(locale)
# set libzypp locale (for communication only, Pkg.SetPackageLocale
# call can be used for installing the language packages)
Yast::Pkg.SetTextLocale(locale)
# TODO: libzypp shows the pattern names and descriptions using the
# locale set at the repository refresh time, here we should refresh
# the repositories with the new locale
# call the language change handler
locale_handler(locale)
end
end

Expand Down Expand Up @@ -101,6 +94,39 @@ def dbus_objects
Agama::DBus::Software::Proposal.new(logger)
]
end

# Language change callback handler, activate new locale in the libzypp backend
# @param locale [String] the new locale
def locale_handler(locale)
# set the locale in the Language module, when changing the repository
# (product) it calls Pkg.SetTextLocale(Language.language) internally
Yast::Language.Set(locale)

# set libzypp locale (for communication only, Pkg.SetPackageLocale
# call can be used for *installing* the language packages)
Yast::Pkg.SetTextLocale(locale)

# refresh all enabled repositories to download the new translation files
Yast::Pkg.SourceGetCurrent(true).each do |src|
Yast::Pkg.SourceForceRefreshNow(src)
end

# remember the currently selected packages and patterns by YaST
# (ignore the automatic selections done by the solver)
#
# NOTE: we will need to handle also the tabooed and soft-locked objects
# when we allow to set them via UI or CLI
selected = Y2Packager::Resolvable.find(status: :selected, transact_by: :appl_high)

# save and reload all repositories to activate the new translations
Yast::Pkg.SourceSaveAll
Yast::Pkg.SourceFinishAll
Yast::Pkg.SourceRestore
Yast::Pkg.SourceLoad

# restore back the selected and locked objects
selected.each { |s| Yast::Pkg.ResolvableInstall(s.name, s.kind) }
end
end
end
end
5 changes: 5 additions & 0 deletions service/package/rubygem-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu Jan 11 12:08:29 UTC 2024 - Ladislav Slezák <lslezak@suse.com>

- Translate the pattern descriptions (gh#openSUSE/agama#859)

-------------------------------------------------------------------
Thu Dec 21 14:23:48 UTC 2023 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down

0 comments on commit 40bc3ed

Please sign in to comment.