001/*
002 * Copyright 2017 Product Mog LLC.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.lokalized;
018
019import javax.annotation.Nonnull;
020import javax.annotation.Nullable;
021import java.util.Locale;
022import java.util.Map;
023
024/**
025 * Contract for localized string providers - given a key and placeholders, return a localized string.
026 * <p>
027 * Format is {@code "You are missing {{requiredFieldCount}} required fields."}
028 *
029 * @author <a href="https://revetkn.com">Mark Allen</a>
030 */
031public interface Strings {
032  /**
033   * Gets a localized string for the given key.
034   * <p>
035   * If no localized string is available, the key is returned.
036   *
037   * @param key the localization key, not null
038   * @return a localized string for the key, not null
039   */
040  @Nonnull
041  String get(@Nonnull String key);
042
043  /**
044   * Gets a localized string for the given key.
045   * <p>
046   * If no localized string is available, the key is returned.
047   *
048   * @param key    the localization key, not null
049   * @param locale the preferred locale for the string, may be null
050   * @return a localized string for the key, not null
051   */
052  @Nonnull
053  String get(@Nonnull String key, @Nullable Locale locale);
054
055  /**
056   * Gets a localized string for the given key.
057   * <p>
058   * If no localized string is available, the key is returned.
059   *
060   * @param key          the localization key, not null
061   * @param placeholders the placeholders to insert into the string, may be null
062   * @return a localized string for the key, not null
063   */
064  @Nonnull
065  String get(@Nonnull String key, @Nullable Map<String, Object> placeholders);
066
067  /**
068   * Gets a localized string for the given key.
069   * <p>
070   * If no localized string is available, the key is returned.
071   *
072   * @param key          the localization key, not null
073   * @param placeholders the placeholders to insert into the string, may be null
074   * @param locale       the preferred locale for the string, may be null
075   * @return a localized string for the key, not null
076   */
077  @Nonnull
078  String get(@Nonnull String key, @Nullable Map<String, Object> placeholders, @Nullable Locale locale);
079}