示例#1
0
文件: time.go 项目: beatgammit/ginta
func (d dateFormat) Convert(locale ginta.Locale, arg interface{}) interface{} {
	if time, ok := arg.(time.Time); ok {
		return EvaluateFormat(common.HierarchicalKey(d), locale, time)
	}

	return arg
}
示例#2
0
func doAddEntry(entry *targetResource) {
	if ptr := universe[entry.target]; ptr != nil {
		prefix, key := types.HierarchicalKey(entry.Key).Split()
		m, ok := ptr.entries[prefix]
		if !ok {
			m = make(bundle)
			ptr.entries[prefix] = m
		}
		m[key] = entry.Value
	}
}
示例#3
0
func work() {
	for {
		select {
		case l := <-registerLanguage:
			doRegister(&l)
		case activate := <-activateLanguage:
			doActivate(&activate)
		case finished := <-fetchFinished:
			doFetchFinished(finished)
		case entry := <-resourceEntry:
			doAddEntry(&entry)
		case request := <-bundleRequests:
			result := make(map[string]string)
			mergeBundles(result, types.HierarchicalKey(request.bundlePrefix), &request)

			request.reply <- result
		case request := <-requests:
			doFetchResource(&request)
		case reply := <-list:
			doListLanguages(reply)
		}
	}
}
示例#4
0
func doFetchResource(request *request) {
	if lang, ok := universe[request.code]; ok {

		iteration := true

		hierarchy := types.HierarchicalKey(request.key)

		for iteration {
			prefix, key := hierarchy.Split()

			if m, ok := lang.entries[prefix]; ok {
				if str, ok := m[key]; ok {
					request.reply <- reply{str, nil}
					return
				}
			}

			hierarchy = hierarchy.Parent()
			iteration = request.recurse && hierarchy.String() != ""
		}
	}

	request.reply <- reply{request.key, types.ResourceNotFoundError(request.key)}
}