001/*
002 * Copyright 2017-2022 Product Mog LLC, 2022-2026 Revetware 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 org.jspecify.annotations.NonNull;
020
021import javax.annotation.concurrent.ThreadSafe;
022
023/**
024 * Observes a translation supplied by a later locale candidate after earlier candidates failed.
025 * <p>
026 * The observer is called once, synchronously, after successful translation and before the lookup returns. It is not
027 * called when the first candidate succeeds, even if locale negotiation used fallback, or when the lookup fails.
028 * Unlike {@link TranslationFallbackPolicy}, it does not decide whether lookup continues, and unlike
029 * {@link TranslationFailureHandler}, it observes a successful outcome.
030 * <p>
031 * An observer exception propagates directly to the caller; it does not become a translation resolution failure or
032 * cause another locale attempt. Implementations shared by a {@link Strings} instance or {@link TranslationOptions}
033 * may be invoked concurrently and must be thread-safe.
034 *
035 * @author <a href="https://revetkn.com">Mark Allen</a>
036 * @since 3.1.1
037 */
038@ThreadSafe
039@FunctionalInterface
040public interface TranslationFallbackObserver {
041
042        /**
043         * Observes successful locale fallback.
044         *
045         * @param translationFallbackEvent diagnostic event for this lookup, not null
046         */
047        void observe(@NonNull TranslationFallbackEvent translationFallbackEvent);
048}