Docsity

OpenJS Foundation messageformat Practice Exam, Exams of Technology

Toggle sidebar
bg1
OpenJS Foundation messageformat
Practice Exam
Question 1. **What syntax does MessageFormat use for simple variable interpolation?**
A) ${variable}
B) {{variable}}
C) {variable}
D) [%variable%]
Answer: C
Explanation: Simple interpolation is done with a single pair of curly braces, e.g., `{name}` inserts
the value of the variable *name*.
Question 2. **How do you escape a literal opening curly brace in a MessageFormat pattern?**
A) \{
B) ''{''
C) '{'
D) {{
Answer: C
Explanation: Single quotes are used to escape characters; writing `'{` produces a literal `{` in the
output.
Question 3. **Which of the following correctly escapes an apostrophe character inside a
MessageFormat string?**
A) \'
B) ''
C) \''
D) \'\'
Answer: B
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c

Partial preview of the text

Download OpenJS Foundation messageformat Practice Exam and more Exams Technology in PDF only on Docsity!

Practice Exam

Question 1. What syntax does MessageFormat use for simple variable interpolation? A) ${variable} B) {{variable}} C) {variable} D) [%variable%] Answer: C Explanation: Simple interpolation is done with a single pair of curly braces, e.g., {name} inserts the value of the variable name. Question 2. How do you escape a literal opening curly brace in a MessageFormat pattern? A) { B) ''{'' C) '{' D) {{ Answer: C Explanation: Single quotes are used to escape characters; writing '{ produces a literal { in the output. Question 3. Which of the following correctly escapes an apostrophe character inside a MessageFormat string? A) ' B) '' C) '' D) '' Answer: B

Practice Exam

Explanation: Two consecutive apostrophes ('') represent a single literal apostrophe in the output. Question 4. In MessageFormat, what is the default argument type when none is specified? A) number B) date C) string D) select Answer: C Explanation: If no type is given, the argument is treated as a plain string and inserted as‑is. Question 5. Which whitespace handling rule is true for MessageFormat patterns? A) All spaces inside braces are ignored. B) Newlines inside a plural block are treated as literal text. C) Leading and trailing spaces outside braces are trimmed. D) Spaces are preserved exactly as they appear. Answer: D Explanation: The parser preserves spaces and newlines exactly; they become part of the formatted message unless explicitly trimmed. Question 6. Which pattern will correctly format a number as currency in US dollars? A) {price, number, currency} B) {price, number, ::currency/USD} C) {price, currency, USD} D) {price, number, ::currency}

Practice Exam

B) It subtracts a constant from the count before category selection. C) It changes the plural category order. D) It forces the use of the other case. Answer: B Explanation: offset:n reduces the actual count by n for the purpose of plural rule evaluation, useful for phrases like “You and X others”. Question 10. Which of the following is a valid exact‑match selector in a plural statement? A) =zero B) = C) =many D) =other Answer: B Explanation: Exact matches are expressed with an equals sign followed by a numeric literal, e.g., =1. Question 11. When using the # token inside a plural case, what does it represent? A) The original count before applying any offset. B) The count after applying any offset. C) The plural category name. D) The literal character #. Answer: B Explanation: # is replaced by the (offset‑adjusted) numeric value for that case. Question 12. Which plural category is required in every plural block to guarantee a fallback?

Practice Exam

A) zero B) one C) many D) other Answer: D Explanation: The other case is mandatory; it is used when no other category matches. Question 13. Select the correct plural pattern for a language that distinguishes “one” and “other” only. A) {count, plural, one{One item} other{# items}} B) {count, plural, =1{One item} other{# items}} C) {count, plural, one{One item} many{# items}} D) {count, plural, =0{No items} other{# items}} Answer: A Explanation: The pattern uses the one and other categories; many languages only need these two. Question 14. What will the following pattern output when count = 0? {count, plural, offset:1 =0{None} one{One} other{# others}} A) None B) One C) - 1 others D) 0 others Answer: A Explanation: The exact match =0 takes precedence, so “None” is chosen regardless of the offset.

Practice Exam

Explanation: Since “guest” does not match any explicit key, the other clause is used, producing “Home”. Question 18. Which select statement correctly handles three gender options and provides a default? A) {gender, select, male{He} female{She} other{They}} B) {gender, select, male{He} female{She} neutral{They}} C) {gender, select, Male{He} Female{She} Other{They}} D) {gender, select, m{He} f{She} o{They}} Answer: A Explanation: The pattern includes male, female, and the mandatory other fallback. Question 19. When nesting a plural inside a select, which of the following is syntactically correct? A) {type, select, photo{{count, plural, one{One photo} other{# photos}}} other{No media}} B) {type, select, photo{count, plural, one{One photo} other{# photos}} other{No media}} C) {type, select, photo{ {count, plural, one{One photo} other{# photos}} } other{No media}} D) {type, select, photo{count, plural, one{One photo} other{# photos}}} other{No media} Answer: A Explanation: The inner plural must be enclosed in its own braces; option A does this correctly. Question 20. What is a primary reason to avoid circular references in MessageFormat patterns? A) They cause infinite recursion at compile time. B) They produce duplicate messages. C) They break the plural rules.

Practice Exam

D) They are unsupported by the Intl API. Answer: A Explanation: Circular references would cause the compiler to recurse indefinitely, leading to a stack overflow. Question 21. Which of the following number skeletons formats a value as a percent with two fractional digits? A) ::percent fraction‑ 2 B) ::percent precision‑ 2 C) ::percent fraction‑minimum‑ 2 D) ::percent precision‑fraction‑ 2 Answer: B Explanation: precision‑2 after ::percent requests two fractional digits in percent style. Question 22. How would you format a number as an integer with grouping separators using a skeleton? A) ::integer grouping‑on B) ::integer precision‑integer C) ::decimal grouping‑on D) ::decimal precision‑integer Answer: C Explanation: The ::decimal skeleton with grouping‑on (default) yields an integer with thousands separators. Question 23. Which date style produces the most detailed output (including weekday, month name, day, year, time, and timezone)?

Practice Exam

Question 26. In the selectordinal extension, which category would match the number 2 in English? A) one B) two C) few D) other Answer: B Explanation: English defines a distinct two category for the ordinal “2nd”. Question 27. What is the output of {count, selectordinal, one{#st} two{#nd} few{#rd} other{#th}} when count = 4? A) 4st B) 4nd C) 4rd D) 4th Answer: D Explanation: The other case handles numbers not matched by one, two, or few, producing “4th”. Question 28. Which of the following is a correct way to register a custom formatter named upper that transforms a string to uppercase? A) mf.addFormatters({upper: v => v.toUpperCase()}); B) mf.registerFormatter('upper', v => v.toUpperCase()); C) mf.addFormatter('upper', v => v.toUpperCase()); D) mf.formatters.upper = v => v.toUpperCase(); Answer: A

Practice Exam

Explanation: The addFormatters method accepts an object mapping formatter names to functions. Question 29. When using the MessageFormat CLI to compile a file, which flag specifies the output directory? A) – out-dir B) – output C) – dest D) – target Answer: A Explanation: The --out-dir (or -o) flag tells the CLI where to write compiled JavaScript files. Question 30. What is the main performance advantage of pre‑compiling MessageFormat strings? A) Reduced memory usage at runtime. B) Eliminates the need for the Intl API. C) Parsing and AST generation happen only once. D) Allows dynamic locale switching without recompilation. Answer: C Explanation: Pre‑compilation transforms patterns into JavaScript functions ahead of time, avoiding repeated parsing. Question 31. Which property of the MessageFormat constructor sets the default locale for all compiled messages? A) defaultLocale B) locale

Practice Exam

Question 34. If a message contains a variable that is not supplied at runtime, what does MessageFormat output by default? A) Throws an exception. B) Leaves the placeholder unchanged. C) Inserts an empty string. D) Inserts the variable name in brackets. Answer: C Explanation: Missing arguments are treated as empty strings, preventing runtime errors. Question 35. Which BCP‑47 tag correctly identifies Canadian French? A) fr-CA B) fr-FR C) ca-FR D) fr-CAU Answer: A Explanation: The language code fr with region CA denotes French as used in Canada. Question 36. When localizing for a right‑to‑left language, which Unicode control character can be used to ensure proper directionality? A) LRM (Left‑to‑Right Mark) B) RLM (Right‑to‑Left Mark) C) LRE (Left‑to‑Right Embedding) D) PDF (Pop Directional Formatting) Answer: B Explanation: RLM forces the following text to be treated as right‑to‑left, useful for RTL locales.

Practice Exam

Question 37. Which practice helps translators avoid “string concatenation” issues? A) Use separate messages for each fragment. B) Build sentences with placeholders for variables. C) Concatenate translated strings in code. D) Provide context comments only. Answer: B Explanation: Embedding variables as placeholders ({name}) keeps the whole sentence together, reducing the need for translators to re‑order fragments. Question 38. What is the purpose of the # token inside a selectordinal block? A) Represents the original numeric value. B) Represents the ordinal suffix. C) Represents the category name. D) Represents the literal character #. Answer: A Explanation: Similar to plurals, # is replaced by the numeric value in the selected ordinal case. Question 39. Which of the following is a valid way to specify a custom date skeleton for a long format? A) {date, date, ::yMMMMd} B) {date, date, long} C) {date, date, ::yMMMMdEEEE} D) {date, date, ::full} Answer: C

Practice Exam

C) They D) (empty string) Answer: C Explanation: Select keys are case‑sensitive; “Male” does not match “male”, so the other fallback is used. Question 43. Which number style would you choose to display a value as a compact short form (e.g., 1.2K)? A) ::compact-short B) ::short C) ::decimal compact-short D) ::compact-short precision‑integer Answer: A Explanation: The compact-short skeleton produces locale‑aware compact notation like “1.2K”. Question 44. How does MessageFormat treat whitespace inside a plural clause that spans multiple lines? A) It removes all newlines. B) It normalizes indentation to a single space. C) It preserves the line breaks as literal whitespace. D) It throws a syntax error. Answer: C Explanation: Whitespace, including line breaks, inside the clause is kept verbatim, which can affect the final output. Question 45. Which of the following is NOT a valid built‑in plural category in CLDR?

Practice Exam

A) zero B) few C) half D) many Answer: C Explanation: half is not a standard CLDR plural category; the six categories are zero, one, two, few, many, other. Question 46. What is the purpose of the defaultLocale option when constructing a MessageFormat instance? A) It overrides the system locale for all messages. B) It provides a fallback locale when a specific locale is missing. C) It sets the locale for date and time formatting only. D) It disables plural rules. Answer: B Explanation: defaultLocale is used when a message’s locale cannot be resolved, ensuring a graceful fallback. Question 47. Which pattern correctly formats a number as currency with the Euro symbol and two decimal places? A) {price, number, ::currency/EUR precision‑2} B) {price, number, ::currency/EUR} C) {price, number, currency, EUR} D) {price, number, ::currency precision‑2} Answer: A

Practice Exam

C) Include the entire UI screen in the message. D) Rely on developers to infer meaning. Answer: B Explanation: The #. comment syntax is recognized by many translation tools and supplies useful context. Question 51. What will the following pattern output for count = 5? {count, plural, =0{none} one{one} other{# items}} A) none B) one C) 5 items D) # items Answer: C Explanation: Neither =0 nor one matches; the other clause is selected, and # is replaced by the count (5). Question 52. In a plural block, how can you reference the original count when an offset is used? A) Use {count} inside the block. B) Use # (it always shows the original count). C) Use #{count} syntax. D) It is not possible; you must compute it outside. Answer: D Explanation: Once an offset is applied, # reflects the adjusted value; the original count must be passed as a separate argument if needed.

Practice Exam

Question 53. Which of the following skeletons creates a decimal number with at least three integer digits and no fraction? A) ::integer min‑integer‑ 3 B) ::decimal minimum‑integer‑3 maximum‑fraction‑ 0 C) ::decimal precision‑integer‑ 3 D) ::decimal integer‑3 fraction‑ 0 Answer: B Explanation: minimum‑integer‑3 ensures three integer digits, and maximum‑fraction‑0 removes any fraction. Question 54. What is the effect of using selectordinal with the other category only? A) All numbers will receive the same suffix defined in other. B) The formatter will fallback to the plural other category. C) It will throw a runtime error. D) It will ignore the ordinal rules and output the number unchanged. Answer: A Explanation: If only other is defined, every number uses that pattern, which typically includes a generic suffix like “th”. Question 55. Which locale tag correctly represents Mandarin Chinese as used in Taiwan? A) zh-TW B) zh-CN C) zh-HK D) zh-TP Answer: A Explanation: zh-TW specifies Traditional Chinese used in Taiwan.