class Chef::Resource::Locale
def define_resource_requirements
Avoid running this resource on platforms that don't use /etc/locale.conf
def define_resource_requirements requirements.assert(:all_actions) do |a| a.assertion { LOCALE_PLATFORM_FAMILIES.include?(node[:platform_family]) } a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource is not supported on platform family: #{node[:platform_family]}") end requirements.assert(:all_actions) do |a| a.assertion do # RHEL/CentOS type platforms don't have locale-gen # Windows has locale-gen as part of the install, but not in the path which("locale-gen") || windows? end a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource requires the locale-gen tool") end end
def generate_locales
-
(Mixlib::ShellOut::ShellCommandFailed)
- not a supported language or locale
Other tags:
- See: http://manpages.ubuntu.com/manpages/cosmic/man8/locale-gen.8.html -
def generate_locales shell_out!("locale-gen #{unavailable_locales.join(" ")}", timeout: 1800) end
def get_system_locale_windows
-
(String)
- the current value of the System-locale setting.
Other tags:
- See: https://docs.microsoft.com/en-us/powershell/module/international/get-winsystemlocale -
def get_system_locale_windows powershell_exec("Get-WinSystemLocale").result["Name"] end
def lc_all(arg = nil)
-
(Chef::Deprecated)
-
Deprecated:
- Use {#lc_env} instead of this property.
def lc_all(arg = nil) unless arg.nil? Chef.deprecated(:locale_lc_all, "Changing LC_ALL can break #{ChefUtils::Dist::Infra::PRODUCT}'s parsing of command output in unexpected ways.\n Use one of the more specific LC_ properties as needed.") end end
def new_content
-
(String)
- Contents that are required to be
def new_content @new_content ||= begin content = {} content = new_resource.lc_env.dup if new_resource.lc_env content["LANG"] = new_resource.lang if new_resource.lang content.sort.map { |t| t.join("=") }.join("\n") + "\n" end end
def set_system_locale
Sets the system locale for the current computer.
def set_system_locale if windows? # Sets the system locale for the current computer. # @see https://docs.microsoft.com/en-us/powershell/module/internationalcmdlets/set-winsystemlocale # response = powershell_exec("Set-WinSystemLocale -SystemLocale #{new_resource.lang}") raise response.errors.join(" ") if response.error? else generate_locales unless unavailable_locales.empty? update_locale end end
def unavailable_locales
-
(Array
- Locales that user wants to set but are not available on)
def unavailable_locales @unavailable_locales ||= begin available = shell_out!("locale -a").stdout.split("\n") required = [new_resource.lang, new_resource.lc_env.values].flatten.compact.uniq required - available end end
def update_locale
- See: https://wiki.archlinux.org/index.php/locale#Setting_the_system_locale -
Other tags:
- Note: - This locale change won't affect the current run. At this time it is an exercise
def update_locale file "Updating system locale" do path LOCALE_CONF content new_content end end