def test_BasicStringLocalization(self):

        with translationTo('pig', localeDir=localeDir):

            self.assertEquals(_("All day"), "Allway ayday")

            self.assertEquals(_("%(startTime)s to %(endTime)s") %
                { 'startTime' : 'a', 'endTime' : 'b' },
                "a otay b"
            )
    def test_BasicStringLocalization(self):

        with translationTo('pig', localeDir=localeDir):

            self.assertEquals(_("All day"), "Allway ayday")

            self.assertEquals(
                _("%(startTime)s to %(endTime)s") %
                {'startTime': 'a', 'endTime': 'b'},
                "a otay b"
            )
    def test_processLocalizationFiles(self):
        """
        Make sure that on OS X the .lproj files are converted properly.
        """
        if sys.platform == "darwin":
            tmpdir = self.mktemp()

            settings = ConfigDict({
                "TranslationsDirectory": os.path.join(os.path.dirname(__file__), "data", "translations"),
                "LocalesDirectory": tmpdir,
            })

            processLocalizationFiles(settings)

            self.assertTrue(os.path.exists(os.path.join(tmpdir, "Testlang", "LC_MESSAGES", "calendarserver.mo")))

            with translationTo('Testlang', localeDir=tmpdir):
                self.assertEquals(_("String1"), "string 1")
                self.assertEquals(_("String2"), "string 2")
Beispiel #4
0
    def getEventDetails(self, calendar, language='en'):
        """
        Create a dictionary mapping slot names - specifically: summary,
        description, location, dateInfo, timeInfo, durationInfo, recurrenceInfo,
        url - with localized string values that should be placed into the HTML
        and plain-text templates.

        @param calendar: a L{Component} upon which to base the language.
        @type calendar: L{Component}

        @param language: a 2-letter language code.
        @type language: C{str}

        @return: a mapping from template slot name to localized text.
        @rtype: a C{dict} mapping C{bytes} to C{unicode}.
        """

        # Get the most appropriate component
        component = calendar.mainComponent()

        results = {}

        dtStart = component.propertyValue('DTSTART')
        results['month'] = dtStart.getMonth()
        results['day'] = dtStart.getDay()

        for propertyToResult in ['summary', 'description', 'location', 'url']:
            result = component.propertyValue(propertyToResult.upper())
            if result is None:
                result = u""
            else:
                result = result.decode('utf-8')
            results[propertyToResult] = result

        with translationTo(language) as trans:
            results['dateInfo'] = trans.date(component).decode('utf-8')
            results['timeInfo'], duration = (x.decode('utf-8')
                                             for x in trans.time(component))
            results['durationInfo'] = u"(%s)" % (
                duration, ) if duration else u""

            for propertyName in ('RRULE', 'RDATE', 'EXRULE', 'EXDATE',
                                 'RECURRENCE-ID'):
                if component.hasProperty(propertyName):
                    results['recurrenceInfo'] = _("(Repeating)").decode(
                        'utf-8')
                    break
            else:
                results['recurrenceInfo'] = u""

        return results
    def getEventDetails(self, calendar, language='en'):
        """
        Create a dictionary mapping slot names - specifically: summary,
        description, location, dateInfo, timeInfo, durationInfo, recurrenceInfo,
        url - with localized string values that should be placed into the HTML
        and plain-text templates.

        @param calendar: a L{Component} upon which to base the language.
        @type calendar: L{Component}

        @param language: a 2-letter language code.
        @type language: C{str}

        @return: a mapping from template slot name to localized text.
        @rtype: a C{dict} mapping C{bytes} to C{unicode}.
        """

        # Get the most appropriate component
        component = calendar.masterComponent()
        if component is None:
            component = calendar.mainComponent(True)

        results = {}

        dtStart = component.propertyValue('DTSTART')
        results['month'] = dtStart.getMonth()
        results['day'] = dtStart.getDay()

        for propertyToResult in ['summary', 'description', 'location', 'url']:
            result = component.propertyValue(propertyToResult.upper())
            if result is None:
                result = u""
            else:
                result = result.decode('utf-8')
            results[propertyToResult] = result

        with translationTo(language) as trans:
            results['dateInfo'] = trans.date(component).decode('utf-8')
            results['timeInfo'], duration = (x.decode('utf-8') for x in trans.time(component))
            results['durationInfo'] = u"(%s)" % (duration,) if duration else u""

            for propertyName in ('RRULE', 'RDATE', 'EXRULE', 'EXDATE',
                                 'RECURRENCE-ID'):
                if component.hasProperty(propertyName):
                    results['recurrenceInfo'] = _("(Repeating)").decode('utf-8')
                    break
            else:
                results['recurrenceInfo'] = u""

        return results
def localizedLabels(language, canceled, inviteState):
    """
    Generate localized labels for an email in the given language.

    @param language: a 2-letter language code

    @type language: C{str}

    @return: a 2-tuple of (subjectFormatString, labelDict), where the first is a
        format string for use in the subject, and the latter is a dictionary
        with labels suitable for filling out HTML and plain-text templates.  All
        values are C{str}s.
    """
    with translationTo(language):
        if canceled:
            subjectFormatString = _("Event canceled: %(summary)s")
        elif inviteState == "new":
            subjectFormatString = _("Event invitation: %(summary)s")
        elif inviteState == "update":
            subjectFormatString = _("Event update: %(summary)s")
        else:
            subjectFormatString = _("Event reply: %(summary)s")

        if canceled:
            inviteLabel = _("Event Canceled")
        else:
            if inviteState == "new":
                inviteLabel = _("Event Invitation")
            elif inviteState == "update":
                inviteLabel = _("Event Update")
            else:
                inviteLabel = _("Event Reply")

        labels = dict(
            dateLabel=_("Date"),
            timeLabel=_("Time"),
            durationLabel=_("Duration"),
            recurrenceLabel=_("Occurs"),
            descLabel=_("Description"),
            urlLabel=_("URL"),
            orgLabel=_("Organizer"),
            attLabel=_("Attendees"),
            locLabel=_("Location"),
            inviteLabel=inviteLabel,
        )

        # The translations we get back from gettext are utf-8 encoded
        # strings, so convert to unicode
        for key in labels.keys():
            if isinstance(labels[key], str):
                labels[key] = labels[key].decode("utf-8")

    return subjectFormatString.decode("utf-8"), labels
Beispiel #7
0
def localizedLabels(language, canceled, inviteState):
    """
    Generate localized labels for an email in the given language.

    @param language: a 2-letter language code

    @type language: C{str}

    @return: a 2-tuple of (subjectFormatString, labelDict), where the first is a
        format string for use in the subject, and the latter is a dictionary
        with labels suitable for filling out HTML and plain-text templates.  All
        values are C{str}s.
    """
    with translationTo(language):
        if canceled:
            subjectFormatString = _("Event canceled: %(summary)s")
        elif inviteState == "new":
            subjectFormatString = _("Event invitation: %(summary)s")
        elif inviteState == "update":
            subjectFormatString = _("Event update: %(summary)s")
        else:
            subjectFormatString = _("Event reply: %(summary)s")

        if canceled:
            inviteLabel = _("Event Canceled")
        else:
            if inviteState == "new":
                inviteLabel = _("Event Invitation")
            elif inviteState == "update":
                inviteLabel = _("Event Update")
            else:
                inviteLabel = _("Event Reply")

        labels = dict(
            dateLabel=_("Date"),
            timeLabel=_("Time"),
            durationLabel=_("Duration"),
            recurrenceLabel=_("Occurs"),
            descLabel=_("Description"),
            urlLabel=_("URL"),
            orgLabel=_("Organizer"),
            attLabel=_("Attendees"),
            locLabel=_("Location"),
            inviteLabel=inviteLabel,
        )

        # The translations we get back from gettext are utf-8 encoded
        # strings, so convert to unicode
        for key in labels.keys():
            if isinstance(labels[key], str):
                labels[key] = labels[key].decode("utf-8")

    return subjectFormatString.decode("utf-8"), labels