Exemple #1
0
class I18N_Manager( dict ):
	"""
	This class handles the :class:`.I18N` instances within an UMC
	session.

	As the UMC server handles all sessions opened on a system that may
	all use a different language it uses one :class:`.I18N_Manager` per
	session.
	"""
	def __init__( self ):
		lang, codeset = getdefaultlocale()
		if lang is None:
			lang = 'C'
		self.locale = Locale( lang )

	def set_locale( self, locale ):
		"""
		Sets the locale to use within the :class:`.I18N_Manager`.

		:param str locale: locale to use
		"""
		LOCALE.info( 'Setting locale to %s' % locale )
		self.locale.parse( locale )
		for domain, i18n in self.items():
			LOCALE.info( 'Loading translation for domain %s' % domain )
			i18n.load( locale = self.locale )

	def __setitem__( self, key, value ):
		value.domain = key
		dict.__setitem__( self, key, value )

	def _( self, message, domain = None ):
		"""
		Translates the given text. Therefor all known translation
		domains or if not None the given domain is searched for a
		translation.

		:param str message: text to translation
		:param str domain: translation domain
		"""
		LOCALE.info( 'Searching for %s translation of "%s' % ( str( self.locale ), message ) )
		if domain is not None:
			if not domain in self:
				self[ domain ] = I18N( self.locale, domain )
			return self[ domain ]._( message )
		for domain, i18n in self.items():
			LOCALE.info( 'Checking domain %s for translation' % domain )
			if i18n.exists( message ):
				return i18n._( message )

		return message
Exemple #2
0
	def __init__( self ):
		lang, codeset = getdefaultlocale()
		if lang is None:
			lang = 'C'
		self.locale = Locale( lang )
def auto_complete_values_for_join(newValues, current_locale=None):
    # try to automatically determine the domain, except on a dcmaster and basesystem
    if newValues[
            'server/role'] != 'domaincontroller_master' and not newValues.get(
                'domainname') and newValues['server/role'] != 'basesystem':
        ucr.load()
        for nameserver in ('nameserver1', 'nameserver2', 'nameserver3'):
            if newValues.get('domainname'):
                break
            newValues['domainname'] = get_ucs_domain(
                newValues.get(nameserver, ucr.get(nameserver)))
        if not newValues['domainname']:
            raise Exception(
                _('Cannot automatically determine the domain. Please specify the server\'s fully qualified domain name.'
                  ))

    # The check "and 'domainname' in newValues" is solely for basesystems
    isAdMember = 'ad/member' in newValues and 'ad/address' in newValues
    if 'windows/domain' not in newValues:
        if isAdMember:
            MODULE.process('Searching for NETBIOS domain in AD')
            for nameserver in ('nameserver1', 'nameserver2', 'nameserver3'):
                ns = newValues.get(nameserver, ucr.get(nameserver))
                if ns:
                    try:
                        ad_domain_info = lookup_adds_dc(
                            newValues.get('ad/address'),
                            ucr={'nameserver1': ns})
                    except failedADConnect:
                        pass
                    else:
                        newValues['windows/domain'] = ad_domain_info[
                            'Netbios Domain']
                        MODULE.process(
                            'Setting NETBIOS domain to AD value: %s' %
                            newValues['windows/domain'])
                        break

    if 'windows/domain' not in newValues and 'domainname' in newValues:
        newValues['windows/domain'] = domain2windowdomain(
            newValues.get('domainname'))
        MODULE.process('Setting NETBIOS domain to default: %s' %
                       newValues['windows/domain'])

    # make sure that AD connector package is installed if AD member mode is chosen
    selectedComponents = set(newValues.get('components', []))
    if isAdMember and newValues['server/role'] == 'domaincontroller_master':
        selectedComponents.add('univention-ad-connector')

    # make sure to install the memberof overlay if it is installed on the DC Master
    if newValues['server/role'] not in ('domaincontroller_master',
                                        'basesystem', 'memberserver'):
        if newValues.pop('install_memberof_overlay', None):
            selectedComponents.add('univention-ldap-overlay-memberof')

    # add lists with all packages that should be removed/installed on the system
    if selectedComponents:
        currentComponents = set()
        for iapp in get_apps():
            if iapp['is_installed']:
                for ipackages in (iapp['default_packages'],
                                  iapp['default_packages_master']):
                    currentComponents = currentComponents.union(ipackages)

        # set of all available software packages
        allComponents = set(['univention-ldap-overlay-memberof'])
        for iapp in get_apps():
            for ipackages in (iapp['default_packages'],
                              iapp['default_packages_master']):
                allComponents = allComponents.union(ipackages)

        # get all packages that shall be removed
        removeComponents = list(allComponents
                                & (currentComponents - selectedComponents))
        newValues['packages_remove'] = ' '.join(removeComponents)

        # get all packages that shall be installed
        installComponents = list(allComponents
                                 & (selectedComponents - currentComponents))
        newValues['packages_install'] = ' '.join(installComponents)

    current_locale = Locale(ucr.get('locale/default', 'en_US.UTF-8:UTF-8'))
    if newValues['server/role'] == 'domaincontroller_master':
        # add newValues for SSL UCR variables
        default_locale = current_locale
        if 'locale/default' in newValues:
            default_locale = Locale(newValues['locale/default'])
        newValues['ssl/state'] = default_locale.territory
        newValues['ssl/locality'] = default_locale.territory
        newValues['ssl/organization'] = newValues.get('organization',
                                                      default_locale.territory)
        newValues['ssl/organizationalunit'] = 'Univention Corporate Server'
        newValues['ssl/email'] = 'ssl@{domainname}'.format(**newValues)

    # make sure that the locale of the current session is also supported
    # ... otherwise the setup scripts will fail after regenerating the
    # locale data (in 20_language/10language) with some strange python
    # exceptions about unsupported locale strings...
    if 'locale' not in newValues:
        newValues['locale'] = newValues.get('locale/default', '')
    forcedLocales = ['en_US.UTF-8:UTF-8', 'de_DE.UTF-8:UTF-8'
                     ]  # we need en_US and de_DE locale as default language
    if current_locale:
        current_locale = '{0}:{1}'.format(str(current_locale),
                                          current_locale.codeset)
        forcedLocales.append(current_locale)
    for ilocale in forcedLocales:
        if ilocale not in newValues['locale']:
            newValues['locale'] = '%s %s' % (newValues['locale'], ilocale)

    return newValues
Exemple #4
0
	def set_locale(self, _locale):
		self.set_language(_locale)
		_locale = str(Locale(_locale))
		locale.setlocale(locale.LC_MESSAGES, _locale)
		locale.setlocale(locale.LC_CTYPE, _locale)