@@ -1915,297 +1915,64 @@ char *get_choice_translation(PrinterCUPS *p,
19151915 return copy ;
19161916}
19171917
1918- char * get_human_readable_option_name (const char * option_name )
1919- {
1920- if (strcmp ("page-set" , option_name ) == 0 )
1921- return cpdbGetStringCopy ("Page set" );
1922- if (strcmp ("position" , option_name ) == 0 )
1923- return cpdbGetStringCopy ("Position" );
1924- if (strcmp ("number-up" , option_name ) == 0 )
1925- return cpdbGetStringCopy ("Pages per side" );
1926- if (strcmp ("number-up-layout" , option_name ) == 0 )
1927- return cpdbGetStringCopy ("Multiple Page layout" );
1928- if (strcmp ("print-resolution" , option_name ) == 0 )
1929- return cpdbGetStringCopy ("Resolution" );
1930- if (strcmp ("print-quality" , option_name ) == 0 )
1931- return cpdbGetStringCopy ("Quality" );
1932- if (strcmp ("printer-resolution" , option_name ) == 0 )
1933- return cpdbGetStringCopy ("Printer resolution" );
1934- if (strcmp ("sides" , option_name ) == 0 )
1935- return cpdbGetStringCopy ("Two-sided" );
1936- if (strcmp ("multiple-document-handling" , option_name ) == 0 )
1937- return cpdbGetStringCopy ("Collate" );
1938- if (strcmp ("media" , option_name ) == 0 )
1939- return cpdbGetStringCopy ("Paper size" );
1940- if (strcmp ("page-delivery" , option_name ) == 0 )
1941- return cpdbGetStringCopy ("Reverse" );
1942- if (strcmp ("page-border" , option_name ) == 0 )
1943- return cpdbGetStringCopy ("Page border" );
1944- if (strcmp ("job-hold-until" , option_name ) == 0 )
1945- return cpdbGetStringCopy ("Print job at" );
1946- if (strcmp ("job-priority" , option_name ) == 0 )
1947- return cpdbGetStringCopy ("Priority" );
1948- if (strcmp ("job-name" , option_name ) == 0 )
1949- return cpdbGetStringCopy ("Job name" );
1950- if (strcmp ("output-bin" , option_name ) == 0 )
1951- return cpdbGetStringCopy ("Output tray" );
1952- if (strcmp ("page-ranges" , option_name ) == 0 )
1953- return cpdbGetStringCopy ("Range" );
1954- if (strcmp ("print-color-mode" , option_name ) == 0 )
1955- return cpdbGetStringCopy ("Color mode" );
1956- if (strcmp ("copies" , option_name ) == 0 )
1957- return cpdbGetStringCopy ("Copies" );
1958- if (strcmp ("orientation-requested" , option_name ) == 0 )
1959- return cpdbGetStringCopy ("Orientation" );
1960- if (strcmp ("job-sheets" , option_name ) == 0 )
1961- return cpdbGetStringCopy ("Paper type" );
1962- if (strcmp ("finishings" , option_name ) == 0 )
1963- return cpdbGetStringCopy ("Finishings" );
1964- if (strcmp ("print-scaling" , option_name ) == 0 )
1965- return cpdbGetStringCopy ("Page scaling" );
1966- if (strcmp ("booklet" , option_name ) == 0 )
1967- return cpdbGetStringCopy ("Booklet" );
1968- if (strcmp ("mirror" , option_name ) == 0 )
1969- return cpdbGetStringCopy ("Mirror" );
1970- return cpdbGetStringCopy (option_name );
1971- }
1972-
1973- char * get_human_readable_choice_name (const char * option_name , const char * choice_name )
1974- {
1975- if (strcmp ("page-set" , option_name ) == 0 )
1976- {
1977- if (strcmp ("all" , choice_name ) == 0 )
1978- return cpdbGetStringCopy ("All pages" );
1979- if (strcmp ("odd" , choice_name ) == 0 )
1980- return cpdbGetStringCopy ("Odd pages" );
1981- if (strcmp ("even" , choice_name ) == 0 )
1982- return cpdbGetStringCopy ("Even pages" );
1983- }
1984- if (strcmp ("position" , option_name ) == 0 )
1985- {
1986- if (strcmp ("center" , choice_name ) == 0 )
1987- return cpdbGetStringCopy ("Center" );
1988- if (strcmp ("top" , choice_name ) == 0 )
1989- return cpdbGetStringCopy ("Top" );
1990- if (strcmp ("bottom" , choice_name ) == 0 )
1991- return cpdbGetStringCopy ("Bottom" );
1992- if (strcmp ("left" , choice_name ) == 0 )
1993- return cpdbGetStringCopy ("Left" );
1994- if (strcmp ("right" , choice_name ) == 0 )
1995- return cpdbGetStringCopy ("Right" );
1996- if (strcmp ("top-left" , choice_name ) == 0 )
1997- return cpdbGetStringCopy ("Top Left" );
1998- if (strcmp ("top-right" , choice_name ) == 0 )
1999- return cpdbGetStringCopy ("Top Right" );
2000- if (strcmp ("bottom-left" , choice_name ) == 0 )
2001- return cpdbGetStringCopy ("Bottom Left" );
2002- if (strcmp ("bottom-right" , choice_name ) == 0 )
2003- return cpdbGetStringCopy ("Bottom Right" );
2004- }
2005- if (strcmp ("number-up-layout" , option_name ) == 0 )
2006- {
2007- if (strcmp ("lrtb" , choice_name ) == 0 )
2008- return cpdbGetStringCopy ("Left to Right, Top to Bottom" );
2009- if (strcmp ("lrbt" , choice_name ) == 0 )
2010-
2011- return cpdbGetStringCopy ("Left to Right, Bottom to Top" );
2012- if (strcmp ("rltb" , choice_name ) == 0 )
2013- return cpdbGetStringCopy ("Right to Left, Top to Bottom" );
2014- if (strcmp ("rlbt" , choice_name ) == 0 )
2015- return cpdbGetStringCopy ("Right to Left, Bottom to Top" );
2016- if (strcmp ("tblr" , choice_name ) == 0 )
2017- return cpdbGetStringCopy ("Top to Bottom, Left to Right" );
2018- if (strcmp ("tbrl" , choice_name ) == 0 )
2019- return cpdbGetStringCopy ("Top to Bottom, Right to Left" );
2020- if (strcmp ("btlr" , choice_name ) == 0 )
2021- return cpdbGetStringCopy ("Bottom to Top, Left to Right" );
2022- if (strcmp ("btrl" , choice_name ) == 0 )
2023- return cpdbGetStringCopy ("Bottom to Top, Right to Left" );
2024- }
2025- if (strcmp ("print-quality" , option_name ) == 0 )
2026- {
2027- if (strcmp ("3" , choice_name ) == 0 || strcasecmp ("draft" , choice_name ) == 0 )
2028- return cpdbGetStringCopy ("Draft" );
2029- if (strcmp ("4" , choice_name ) == 0 || strcasecmp ("normal" , choice_name ) == 0 )
2030- return cpdbGetStringCopy ("Normal" );
2031- if (strcmp ("5" , choice_name ) == 0 || strcasecmp ("high" , choice_name ) == 0 )
2032- return cpdbGetStringCopy ("High" );
2033- }
2034- if (strcmp ("sides" , option_name ) == 0 )
2035- {
2036- if (strcmp ("one-sided" , choice_name ) == 0 )
2037- return cpdbGetStringCopy ("Off" );
2038- if (strcmp ("two-sided-short-edge" , choice_name ) == 0 )
2039- return cpdbGetStringCopy ("On, Landscape" );
2040- if (strcmp ("two-sided-long-edge" , choice_name ) == 0 )
2041- return cpdbGetStringCopy ("On, Potrait" );
2042- }
2043- if (strcmp ("multiple-document-handling" , option_name ) == 0 )
1918+ GVariant * get_printer_translations (PrinterCUPS * p , const char * locale )
1919+ {
1920+ int num_opts ;
1921+ Option * opts ;
1922+ GVariant * translations ;
1923+ GVariantBuilder * builder ;
1924+
1925+ char * group ;
1926+ char * name_tr , * group_tr , * choice_tr ;
1927+ char * name_key , * group_key , * choice_key ;
1928+
1929+ num_opts = get_all_options (p , & opts );
1930+ builder = g_variant_builder_new (G_VARIANT_TYPE (CPDB_TL_DICT_ARGS ));
1931+ for (int i = 0 ; i < num_opts ; i ++ )
20441932 {
2045-
2046- if (strcmp ("separate-documents-uncollated-copies" , choice_name ) == 0 )
2047- return cpdbGetStringCopy ("Off" );
2048- if (strcmp ("separate-documents-collated-copies" , choice_name ) == 0 )
2049- return cpdbGetStringCopy ("On" );
1933+ /* add translation for option name */
1934+ name_tr = get_option_translation (p , opts [i ].option_name , locale );
1935+ name_key = cpdbConcatSep (CPDB_OPT_PREFIX , opts [i ].option_name );
1936+ if (name_tr )
1937+ {
1938+ logdebug ("Translation '%s' : '%s'\n" , name_key , name_tr );
1939+ g_variant_builder_add (builder , CPDB_TL_ARGS , name_key , name_tr );
1940+ }
1941+ g_free (name_tr );
1942+
1943+ /* add translation for option group */
1944+ group = cpdbGetGroup (opts [i ].option_name );
1945+ group_key = cpdbConcatSep (CPDB_GRP_PREFIX , group );
1946+ group_tr = cpdbGetGroupTranslation2 (group , locale );
1947+ if (group_tr )
1948+ {
1949+ logdebug ("Translation '%s' : '%s'\n" , group_key , group_tr );
1950+ g_variant_builder_add (builder , CPDB_TL_ARGS , group_key , group_tr );
1951+ }
1952+ g_free (group );
1953+ g_free (group_key );
1954+ g_free (group_tr );
1955+
1956+ /* add translation for option choices */
1957+ for (int j = 0 ; j < opts [i ].num_supported ; j ++ )
1958+ {
1959+ choice_tr = get_choice_translation (p , opts [i ].option_name , opts [i ].supported_values [j ], locale );
1960+ choice_key = cpdbConcatSep (name_key , opts [i ].supported_values [j ]);
1961+ if (choice_tr )
1962+ {
1963+ logdebug ("Translation '%s' : '%s'\n" , choice_key , choice_tr );
1964+ g_variant_builder_add (builder , CPDB_TL_ARGS , choice_key , choice_tr );
1965+ }
1966+ g_free (choice_key );
1967+ g_free (choice_tr );
1968+ }
1969+
1970+ g_free (name_key );
20501971 }
2051- if (strcmp ("media" , option_name ) == 0 )
2052- {
2053- pwg_media_t * pwg_media ;
2054-
2055- pwg_media = pwgMediaForPWG (choice_name );
2056- if (pwg_media != NULL )
2057- return cpdbGetStringCopy (pwg_media -> ppd );
2058- }
2059- if (strcmp ("page-delivery" , option_name ) == 0 )
2060- {
2061- if (strcmp ("same-order" , choice_name ) == 0 )
2062- return cpdbGetStringCopy ("Off" );
2063- if (strcmp ("reverse-order" , choice_name ) == 0 )
2064- return cpdbGetStringCopy ("On" );
2065- }
2066- if (strcmp ("page-border" , option_name ) == 0 )
2067- {
2068- if (strcmp ("none" , choice_name ) == 0 )
2069- return cpdbGetStringCopy ("None" );
2070- if (strcmp ("single" , choice_name ) == 0 )
2071- return cpdbGetStringCopy ("Single" );
2072- if (strcmp ("single-thick" , choice_name ) == 0 )
2073- return cpdbGetStringCopy ("Single Thick" );
2074- if (strcmp ("double" , choice_name ) == 0 )
2075- return cpdbGetStringCopy ("Double" );
2076- if (strcmp ("double" , choice_name ) == 0 )
2077- return cpdbGetStringCopy ("Double Thick" );
2078- }
2079- if (strcmp ("job-hold-until" , option_name ) == 0 )
2080- {
2081- if (strcmp ("no-hold" , choice_name ) == 0 )
2082- return cpdbGetStringCopy ("No hold" );
2083- if (strcmp ("indefinite" , choice_name ) == 0 )
2084- return cpdbGetStringCopy ("Indefinite" );
2085- if (strcmp ("day-time" , choice_name ) == 0 )
2086- return cpdbGetStringCopy ("Day time" );
2087- if (strcmp ("evening" , choice_name ) == 0 )
2088- return cpdbGetStringCopy ("Evening" );
2089- if (strcmp ("night" , choice_name ) == 0 )
2090- return cpdbGetStringCopy ("Night" );
2091- if (strcmp ("second-shift" , choice_name ) == 0 )
2092- return cpdbGetStringCopy ("Second shift" );
2093- if (strcmp ("third-shift" , choice_name ) == 0 )
2094- return cpdbGetStringCopy ("Third shift" );
2095- if (strcmp ("weekend" , choice_name ) == 0 )
2096- return cpdbGetStringCopy ("Weekend" );
2097- }
2098- if (strcmp ("job-priority" , option_name ) == 0 )
2099- {
2100- int val = atoi (choice_name );
2101-
2102- if (val <= 30 )
2103- return cpdbGetStringCopy ("Low" );
2104- if (val <= 50 )
2105- return cpdbGetStringCopy ("Medium" );
2106- if (val <= 80 )
2107- return cpdbGetStringCopy ("High" );
2108- if (val <= 100 )
2109- return cpdbGetStringCopy ("Urgent" );
2110- }
2111- if (strcmp ("output-bin" , option_name ) == 0 )
2112- {
2113- if (strcmp ("top" , choice_name ) == 0 )
2114- return cpdbGetStringCopy ("Top bin" );
2115- if (strcmp ("middle" , choice_name ) == 0 )
2116- return cpdbGetStringCopy ("Middle bin" );
2117- if (strcmp ("bottom" , choice_name ) == 0 )
2118- return cpdbGetStringCopy ("Bottom bin" );
2119- if (strcmp ("side" , choice_name ) == 0 )
2120- return cpdbGetStringCopy ("Side bin" );
2121- if (strcmp ("left" , choice_name ) == 0 )
2122- return cpdbGetStringCopy ("Left bin" );
2123- if (strcmp ("right" , choice_name ) == 0 )
2124- return cpdbGetStringCopy ("Right bin" );
2125- if (strcmp ("center" , choice_name ) == 0 )
2126- return cpdbGetStringCopy ("Center bin" );
2127- if (strcmp ("rear" , choice_name ) == 0 )
2128- return cpdbGetStringCopy ("Rear bin" );
2129- if (strcmp ("face-down" , choice_name ) == 0 )
2130- return cpdbGetStringCopy ("Face Down Bin" );
2131- if (strcmp ("face-up" , choice_name ) == 0 )
2132- return cpdbGetStringCopy ("Face up Bin" );
2133- if (strcmp ("large-capacity" , choice_name ) == 0 )
2134- return cpdbGetStringCopy ("Large Capacity bin" );
2135- }
2136- if (strcmp ("print-color-mode" , option_name ) == 0 )
2137- {
2138- if (strcmp ("monochrome" , choice_name ) == 0 )
2139- return cpdbGetStringCopy ("Monochrome" );
2140- if (strcmp ("color" , choice_name ) == 0 )
2141- return cpdbGetStringCopy ("Color" );
2142- }
2143- if (strcmp ("orientation-requested" , option_name ) == 0 )
2144- {
2145- if (strcmp ("3" , choice_name ) == 0 )
2146- return cpdbGetStringCopy ("Potrait" );
2147- if (strcmp ("4" , choice_name ) == 0 )
2148- return cpdbGetStringCopy ("Landscape" );
2149- if (strcmp ("5" , choice_name ) == 0 )
2150- return cpdbGetStringCopy ("Reverse Landscape" );
2151- if (strcmp ("6" , choice_name ) == 0 )
2152- return cpdbGetStringCopy ("Reverse Potrait" );
2153- }
2154- if (strcmp ("job-sheets" , option_name ) == 0 )
2155- {
2156- if (strcmp ("none" , choice_name ) == 0 )
2157- return cpdbGetStringCopy ("None" );
2158- if (strcmp ("classified" , choice_name ) == 0 )
2159- return cpdbGetStringCopy ("Classified" );
2160- if (strcmp ("confidential" , choice_name ) == 0 )
2161- return cpdbGetStringCopy ("Confidential" );
2162- if (strcmp ("form" , choice_name ) == 0 )
2163- return cpdbGetStringCopy ("Form" );
2164- if (strcmp ("secret" , choice_name ) == 0 )
2165- return cpdbGetStringCopy ("Secret" );
2166- if (strcmp ("standard" , choice_name ) == 0 )
2167- return cpdbGetStringCopy ("Standard" );
2168- if (strcmp ("topsecret" , choice_name ) == 0 )
2169- return cpdbGetStringCopy ("Topsecret" );
2170- if (strcmp ("unclassified" , choice_name ) == 0 )
2171- return cpdbGetStringCopy ("Unclassified" );
2172- }
2173- if (strcmp ("finishings" , option_name ) == 0 )
2174- {
2175- if (strcmp ("none" , choice_name ) == 0 )
2176- return cpdbGetStringCopy ("None" );
2177- }
2178- if (strcmp ("print-scaling" , option_name ) == 0 )
2179- {
2180- if (strcmp ("auto" , choice_name ) == 0 )
2181- return cpdbGetStringCopy ("Auto" );
2182- if (strcmp ("auto-fit" , choice_name ) == 0 )
2183- return cpdbGetStringCopy ("Auto-Fit" );
2184- if (strcmp ("fill" , choice_name ) == 0 )
2185- return cpdbGetStringCopy ("Fill" );
2186- if (strcmp ("fit" , choice_name ) == 0 )
2187- return cpdbGetStringCopy ("Fit" );
2188- if (strcmp ("none" , choice_name ) == 0 )
2189- return cpdbGetStringCopy ("None" );
2190- }
2191- if (strcmp ("booklet" , option_name ) == 0 )
2192- {
2193- if (strcmp ("off" , choice_name ) == 0 )
2194- return cpdbGetStringCopy ("Off" );
2195- if (strcmp ("on" , choice_name ) == 0 )
2196- return cpdbGetStringCopy ("On" );
2197- if (strcmp ("shuffle-only" , choice_name ) == 0 )
2198- return cpdbGetStringCopy ("Shuffle" );
2199- }
2200- if (strcmp ("mirror" , option_name ) == 0 )
2201- {
2202- if (strcmp ("off" , choice_name ) == 0 )
2203- return cpdbGetStringCopy ("Off" );
2204- if (strcmp ("on" , choice_name ) == 0 )
2205- return cpdbGetStringCopy ("On" );
2206- }
2207-
2208- return cpdbGetStringCopy (choice_name );
1972+ translations = g_variant_builder_end (builder );
1973+ free_options (num_opts , opts );
1974+
1975+ return translations ;
22091976}
22101977
22111978char * translate_job_state (ipp_jstate_t state )
0 commit comments