Project

General

Profile

Bug #1094 » liborchestrator-zh-locale.diff

Albert Lee, 2011-06-16 05:08 PM

View differences:

usr/src/lib/liborchestrator/locale.c
80 80
	char	*lang_code;
81 81
} chinese_values[] = {
82 82
	{"zh", SIMPLIFIED_CHINESE, "sc"},
83
	{"zh.GBK", SIMPLIFIED_CHINESE, "sc"},
84
	{"zh.UTF-8", SIMPLIFIED_CHINESE, "sc"},
85 83
	{"zh_CN", SIMPLIFIED_CHINESE, "sc"},
86
	{"zh_CN.GB18030", SIMPLIFIED_CHINESE, "sc"},
87
	{"zh_CN.UTF-8", SIMPLIFIED_CHINESE, "sc"},
88 84
	{"zh_HK", TRADITIONAL_CHINESE, "tc"},
89
	{"zh_HK.BIG5HK", TRADITIONAL_CHINESE, "tc"},
90
	{"zh_HK.UTF-8", TRADITIONAL_CHINESE, "tc"},
85
	{"zh_MO", TRADITIONAL_CHINESE, "tc"},
86
	{"zh_SG", TRADITIONAL_CHINESE, "tc"},
91 87
	{"zh_TW", TRADITIONAL_CHINESE, "tc"},
92
	{"zh_TW.BIG5", TRADITIONAL_CHINESE, "tc"},
93
	{"zh_TW.UTF-8", TRADITIONAL_CHINESE, "tc"}
88
	{ NULL }
94 89
};
95 90

  
96 91

  
......
642 637
	lang_info_t	*tmp, *last, *new;
643 638
	locale_info_t	*lp = NULL;
644 639
	char		**trans_lang = NULL;
640
	char		*sub = NULL;
645 641
	char		*tmp_lang = NULL;
646 642
	char		*tmp_locale = NULL;
647 643
	char		*code = NULL;
......
654 650
	 * Chinese or Simplified Chinese. Everything else is a locale.
655 651
	 */
656 652
	if (strncmp(lang, "zh", 2) == 0) {
657
		tmp_lang = strdup(dgettext(TEXT_DOMAIN,
658
		    substitute_chinese_language(lang, &code)));
653
		sub = substitute_chinese_language(lang, &code);
654
		if (sub == NULL)
655
			goto error;
656
		tmp_lang = strdup(dgettext(TEXT_DOMAIN, sub));
657
		if (tmp_lang == NULL) {
658
			goto error;
659 659
		if (locale == NULL)
660 660
			tmp_locale = strdup(dgettext(TEXT_DOMAIN, lang));
661
	}
662
	if (strncmp(lang, "C", 1) == 0) {
663
		tmp_lang = strdup(dgettext(TEXT_DOMAIN,
664
		    substitute_C_POSIX_language(&code)));
661
	} else if (strcmp(lang, "C") == 0 || strcmp(lang, "POSIX") == 0 ||
662
	    strcmp(lang, "C/POSIX") == 0) {
663
		sub = substitute_C_POSIX_language(&code);
664
		tmp_lang = strdup(dgettext(TEXT_DOMAIN, sub));
665
		if (tmp_lang == NULL)
666
			goto error;
665 667
		if (locale == NULL)
666 668
			tmp_locale = strdup(dgettext(TEXT_DOMAIN, lang));
667 669
	}
......
743 745
		list = new;
744 746
	}
745 747

  
746
	free(code);
747 748
	*(return_list) = list;
748 749
	return (OM_SUCCESS);
749 750

  
750 751
error:
751
	free(code);
752 752
	om_free_lang_info(new);
753 753
	om_free_locale_info(lp);
754 754
	return (OM_FAILURE);
......
776 776
get_lang_entry(char *lang_name, lang_info_t *search_list)
777 777
{
778 778
	lang_info_t 	*list = NULL;
779
	char		*tmp_lang = NULL;
779
	char		*sub = NULL;
780 780
	char		*code = NULL;
781 781
	boolean_t	found = B_FALSE;
782 782

  
......
787 787
	 */
788 788

  
789 789
	if (strncmp(lang_name, "zh", 2) == 0)  {
790
		tmp_lang = strdup(dgettext(TEXT_DOMAIN,
791
		    substitute_chinese_language(lang_name, &code)));
790
		sub = substitute_chinese_language(lang, &code);
791
		if (sub == NULL)
792
			return (NULL);
793
	} else if (strcmp(lang_name, "C") == 0 ||
794
	    strcmp(locale, "POSIX") == 0 ||
795
	    strcmp(locale, "C/POSIX") == 0) {
796
		sub = substitute_C_POSIX_language(locale, &code);
792 797
	}
793 798

  
794 799
	for (list = search_list; list != NULL; list = list->next) {
......
805 810
		}
806 811
	}
807 812

  
808
	free(tmp_lang);
809
	free(code);
810

  
811 813
	if (!found)
812 814
		return (NULL);
813 815
	return (list);
......
939 941
				}
940 942
			}
941 943
		} else if (strcmp(lang, "C") == 0 ||
942
		    strcmp(lang, "POSIX") == 0) {
944
		    strcmp(lang, "POSIX") == 0 ||
945
		    strcmp(lang, "C/POSIX") == 0) {
943 946
			free(lang);
944 947
			lang = strdup("en");
945 948
			is_default = B_TRUE;
......
1146 1149
				}
1147 1150
			}
1148 1151
		} else if (strcmp(lang, "C") == 0 ||
1149
		    strcmp(lang, "POSIX") == 0) {
1152
		    strcmp(lang, "POSIX") == 0 ||
1153
		    strcmp(lang, "C/POSIX") == 0) {
1150 1154
			free(lang);
1151 1155
			lang = strdup("en");
1152 1156
			if (lang == NULL) {
......
1577 1581
	char	**lpp = *list;
1578 1582
	char	**tmp_list;
1579 1583
	char	*tmp = NULL;
1584
	char	*sub = NULL;
1580 1585
	char	*code;
1581 1586

  
1582 1587
	tmp_list = *list;
1583 1588

  
1584 1589
	if (strncmp(locale, "zh", 2) == 0) {
1585
		tmp = strdup(dgettext(TEXT_DOMAIN,
1586
		    substitute_chinese_language(locale, &code)));
1590
		sub = substitute_chinese_language(locale, &code);
1591
		if (sub == NULL)
1592
			return (OM_FAILURE);
1593
		tmp = strdup(dgettext(TEXT_DOMAIN, sub));
1587 1594
	} else if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0 ||
1588 1595
	    strcmp(locale, "C/POSIX") == 0) {
1589
		tmp = strdup(dgettext(TEXT_DOMAIN, "English"));
1596
		sub = substitute_C_POSIX_language(locale, &code);
1597
		tmp = strdup(dgettext(TEXT_DOMAIN, sub));
1590 1598
	} else {
1591 1599
		tmp = strdup(dgettext(TEXT_DOMAIN,
1592 1600
		    orchestrator_lang_list[j].lang_name));
......
1651 1659
	 * locale is C and or POSIX. Set to English, set code
1652 1660
	 * to 'en'.
1653 1661
	 */
1654
	lang = strdup(dgettext(TEXT_DOMAIN, "English"));
1655
	if (lang == NULL) {
1656
		om_set_error(OM_NO_SPACE);
1657
		*code = NULL;
1658
		return (lang);
1659
	}
1660
	*code = strdup("en");
1661
	if (*code == NULL) {
1662
		free(lang);
1663
		lang = NULL;
1664
		om_set_error(OM_NO_SPACE);
1665
	}
1662
	lang = dgettext(TEXT_DOMAIN, "English");
1663
	*code = "en";
1666 1664
	return (lang);
1667 1665
}
1668 1666

  
......
1670 1668
substitute_chinese_language(char *locale, char **code)
1671 1669
{
1672 1670
	int 		i;
1671
	int		len;
1673 1672
	char		*sub = NULL;
1674 1673

  
1675
	*code = NULL;
1676

  
1677
	for (i = 0; chinese_values[i].lang; i++) {
1678
		if (strcmp(locale, chinese_values[i].lang) == 0) {
1679
			sub = strdup(chinese_values[i].lang_name);
1680
			*code = strdup(chinese_values[i].lang_code);
1681
			if (sub == NULL || *code == NULL) {
1682
				free(sub);
1683
				om_set_error(OM_NO_SPACE);
1684
				return (NULL);
1685
			} else {
1674
	for (i = 0; chinese_values[i].lang != NULL; i++) {
1675
		len = strlen(chinese_values[i].lang);
1676
		if ((strncmp(locale,  chinese_values[i].lang, len) == 0) &&
1677
		    (locale[len] == '\0' || locale[len] == '.')) {
1678
			sub = chinese_values[i].lang_name;
1679
			*code = chinese_values[i].lang_code;
1686 1680
				return (sub);
1687 1681
			}
1688 1682
		}
1689 1683
	}
1684

  
1685
	*code = NULL;
1686
	om_set_error(OM_INVALID_LOCALE);
1690 1687
	return (sub);
1691 1688
}
1692 1689

  
(2-2/2)